Hello, this is Dr. Miller, and this
is Episode eleven point one of
assembly.
Today, we're going to talk about the
arm architecture,
the ARM architecture.
So Arm originally stood for
the ACORN risk machine
or later the advanced risk
machine, and this is a
family of reduced construction site
architectures.
So if we compare that to Intel,
Intel is a complex
construction site computing
architecture, which means we have
lots more instructions
that we can use.
And in a risk
system, we have less instructions.
But if you look at the arm design,
we actually have less transistors.
So we this amount of
less transistors causes us to
generate less heat and also
use less energy.
And thus ARM is used on
most mobile devices.
So most cell phones
and tablets are going to run arm
and then we do have 32 and 64
bit. And then there's an additional
THOMOND, which we'll talk about at
some point in the future.
So what ALM does is they actually
create the designs for chips
so they don't actually create the
chips, they just create the design
and then somebody purchases that
from them and then they sell
these to manufacturers and
fabrication plants.
So with arm assembly, what we're
going to end up using is we're going
to use the ganu assembler or gas
or sometimes just called ass.
And so when we create our program,
we're just going to use the
assembler to do that.
And then we will also still be using
Jasiek in order to do linking.
And then in a future lecture, we'll
talk about the template and a
makefile and project folders
and then we'll use the Ganu Assembly
syntax. So this will be different
than Mazloum, but it'll all be
related to
the arm architecture.
And then probably the easiest to use
is using a Raspberry Pi with wrasse
being installed.
And so for these lectures, I will
log on to a Raspberry Pi
machine and we will use that
to create our code.
So one of the big differences that
we're going to see is when we return
from a function, we'll go through
that. And what ARM
does is it uses a special register
to do this, and that's because the
registers are a lot faster than the
stack. And so that helps speed up
our programs just a little tiny bit.
And so this is called the Link
Register or L.R..
And then when we talk about
returning or branching,
it's the B so branch
with link, the link register will
jump to the new location and then
set the link registered to where we
where we came from.
And then when we want to
go back, we can do branch exchange
like registering that will return
from a function and we'll get into
more details with that in the
future.
And then we'll have an example here
that will go in and type in in a
little bit.
So one of the other differences is
that ARM includes a whole
bunch of system modes that you
can use.
And so we can see that we have
things like the Fast Interop, Q
or F IQ.
So that is a fast way to interrupt
the processor.
We have General Interrupts or the IQ
and we have a supervisor mode and
this allows a protected mode
which has some instructions you
can't execute.
So that way you can write a kernel
that's in supervisor mode, abort
mode when you have a
abort on an instruction
and then systematize also for
privileged.
And so these different modes
can be used. We won't use these
for our programs, but there
might be instructions that you might
find that will only run
in f IQ or supervisor
mode that won't run in regular mode.
And then four registers we're going
to have 16 registers are
zero through our 15
R zero is going to be our
accumulator register.
Our 13 will typically
see used as ESP four stack
pointer.
Our 14 is our link register.
AR 15 is the program counter
or instruction pointer that we've
looked at in eighty six.
And again, you can use the
shorthands SP LRR PC,
but sometimes when you look at code
that's generated, you might end up
seeing that it talks about AR
15, but then you just got to know
that that's the program counter.
And then we have the current process
status register or CPS
are.
So this is thirty two bits and it
basically holds all of the flags
that we have in
our program.
And so any of the flags that we're
going to have are going to be in
this S.P.C.A.
And that will include overflow carry
negative processer motets
in what interrupt.
Q and fasta interrupt.
Q are said.
And then ARM has several different
operating seats, so the typical
operating state is the 32 bit
weird aligned instructions,
and so that's just what we call
Armon.
Now, they also have a 16 bit
instructions.
So here each of the the instructions
is thirty two bits
or four bytes.
But in the mode they are two bytes.
And so we have a we can get
much more dense code if we use
Thommo. Now some instructions are
not accessible to us
and that way we cannot use them.
So sometimes you have to go back and
forth between our mode and thumb
mode and then
the actual program counter actually
uses a bit one to basically tell
it that it is operating in thumb
mode and that it needs to use half
words instead of forwards
for instructions.
Now the contrast this.
If we look at X eighty six X eighty
six has variable length
instructions. So some instructions
like push only use one byte,
whereas some instructions like move
might use six or seven bytes for
that instruction, whereas ALM
every instruction is the exact same
with depending on if it's an
arm or thumb on.
And then talking about Thum State,
so that is part of the AR 15 or the
program counter says whether or not
you are in THOMOND or not.
And then R.M. also has this notion
of bank registers, we all saw
the different modes that we can
have, but basically bank
registers allow us to maybe
use the same register name,
but we can
access different pieces of data
depending on which mode we can.
And we'll see that in a in a diagram
here. But basically, if it's banked,
then it's preserved across the
different mode changes.
And so if you modify
one of the bank registers, then it
won't get clobbered in a way that
you didn't expect.
And so, for example, the fast
interrupt queue has seven bank
registers,
and so the handlers don't have to
save any of those registers, they
can just use them,
orate MICU
instead of orate.
And then you don't have to worry
about basically pushing them onto
the stack and then saving them and
then popping them off.
And so a diagram this shows
the the little triangle
here is showing which
registers are banked and so
we can see that all
of the R 13 and our 14
are banked across all of the
other modes other than system and
user.
And so that way you don't have to
save those along with
some of the
program status registers.
All right, so let's get into a
a very small program here, so
I'll go ahead and try and take
this in.
So we're going to start off we're
going to create a program called
First
S for Assembly.
Don't know why that that is.
And so here we can use
and instead of using Yak's,
where we're going to use our zero so
we can say move are zero
and we'll talk about numbers, the
number seven
branch exchange with the
link register.
So, again, this is going to this
part is the return from our
function and this
is just moving a return result
into the
accumulator type register.
And then if we type as for
the assembler.
And so the input is first,
what is the output that it's going
to create as first thought?
Oh.
Oh, I forgot the minus.
Oh, they're for output.
And then you can say, OK, minus,
oh, so this is the output for
this, so first
out and the
input that we're going to use is
first. Oh.
And if we run our program.
And then we can say echo
and get the result, the same
question mark, so he's on
our program, we knew moved the
number seven in there and so
the return result is seven.
So additionally, we can
create a makefile for this.
So to build all of the targets we're
going to use first, there's
going to be our main thing.
So to build first,
we require first
dot o and then
the makefile, you've got to use tab
to do the line that you want
to do. So C
minus O first got
out.
And then to build the first object.
The required file or wait for
changes is first
not as
tight as mine is first.
Oh, first,
yes, and then
clean is to clean things up if we
want to just build it from the
scratch.
And this is
I'm going to use first thought out
so clean.
So I named my file here first
that out, so R.M.
is going to remove our
four recursive EF four force, remove
these two files if we try
and do a clean.
So when it tries to build first,
it's going to say what is first
require first requires first
thought. Oh, and so this is how to
build that.
What is first thought.
Oh require
first. That requires first steps.
And so at first that f changes then
it'll do this command and then this
is modified. So then it does this
command and that's how we build our
entire project.
And we'll go ahead and clean.
So, see, we when we build did
make than our our five got
created and so now we can run first
thought out and
if we echo, we'll see that the
number seven was there.
All right, so today we gave a really
brief introduction into the
ARM Architecture and ARM Assembly.
Looking forward, we're going to set
up and use the template
that is created for ARM,
if you have questions, you can email
me millirems at you in Canada,
Aidoo, and you can find me on
Twitter at Malchow Sturdee.