13 hours 15 minutes
Hello. This is Dr Miller, and this is Episode 11.1 of Assembly.
Today we're gonna talk about the arm architecture,
the arm architecture.
So arm originally stood for the Acorn RISC machine or later, the Advanced RISC machine.
And this is a family of reduced instruction set architectures. So if we compare that to Intel, Intel is a complex instruction set computing architecture. Which means we have lots mawr 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 64 bit. And then there's an additional thumb mode, which will talk about at some point in the future.
So what arm 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 two manufacturers and fabrication plants.
So, with arm assembly, what we're gonna end up using is we're going to use the canoe assembler or gas, or sometimes just called s. 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 GCC in order to do linking.
And then, in a future lecture will talk about the template and a make file in project folders,
and then we'll use the canoe assemblies in tax. So this will be different than Moazzam. Better to all be related to,
um, the arm architecture.
And then probably the easiest to use is using a raspberry pi with raspy and installed.
And so, for these lectures, I will log on to a raspberry pied machine, and we will use that to create our code.
So one of the big difference is that we're going to see is when we return from a function, we'll go through that. And what arm does Aziz is a special registered to do this. That's because registers air 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 be so branch. With Link, the Link register will
jump to the new location and then set the link register to where we were we came from.
And then when we want Teoh, go back, weaken do Branch Exchange Link register and that will return from a function, and we'll get into more details with that in the future,
Um, and then we'll have an example here that we're in and type in in a little bit.
So one of the other differences is the arm includes a whole bunch of system modes that you can use
and so we can see that we have things like the fast interrupt Q or F I. Q.
So that is a fast way to interrupt the processor we have General Interrupts or the I R. Q.
We have a supervisor mode, and this allows protected mode, which has some instructions you can't execute.
So that way you can write a colonel that's in supervisor mode abort mode when you have a abort on an instruction and then system motives also for privileged,
um, 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 I Q or supervisor mode that won't run in regular mode
and then for registers, we're gonna have 16. Registers are zero through. Our 15
are zero is going to be our accumulator register are 13 will typically see used as SP for Stack Pointer
are 14 is our link register.
AR 15 is a program Canada or instruction pointer that we've looked at in X 86
and again you can use these short hands spl, RPC.
But sometimes when you look at code that's generated, you might end up seeing that it talks about our 15. But then you just got to know that that's the program counter.
And then we have the current process Status register. CPS are
so this is 32 bits, and it basically holds all of the flags that we have in our program.
And so any of the flags that we're gonna have are going to be in this CPS are, and that'll include overflow Kerry negative what processor mode it's in. What interrupt Q and fast Interrupt You are set
and then Arm has several different operating states. Of the typical operating state is the 32 bit word aligned instructions.
And so that's just what we call our moon
now. They also have a 16 bit instructions. So here each of the the instructions is 32 bits
or four bites. But in thumb mode there two bites. And so we have a We can get much more dense code if we use thumb mode now, some instructions or not
accessible to us,
Um, and that way we cannot use them. So sometimes you have to go back and forth between our mode and thumb bone.
the actual program counter actually uses a bit one to basically tell it that it is operating in thumb mode in that it needs to use half words instead of full words
for instructions. Now, to contrast this, if we look at x 86 X 86 has variable length instructions, so some instructions, like push on lee, use one bite, whereas some instructions, like Move might use six or seven bytes for that instruction.
Where his arm. Every instruction is the exact same with depending on if it's an arm with a moon
and then talking about Thumb State. So that is part of the AR 15 or the program, counter says, whether or not you are in thumb mode or not.
And then arm also has this notion of banked registers. We all did. It saw the different modes that we can have, but basically banked registers allow us to maybe used the same registered name.
But we can access different pieces of data depending on which Modry in.
And we'll see that in a diagram here. But basically, if it's banked than it's preserved across the different mode changes. And so if you modify one of the bank's registers, then it won't get clobbered in a way that you didn't expect.
And so, for example, the fast interrupt Que has seven banked registers,
Um, and so the handlers don't have to save any of those registers. They can just use them, Um, are eight f. I Q instead of our eight, and then you don't have to worry about basically pushing him onto the stack and then saving them and then popping them off
and so a diagram. This shows the little triangle here is showing which registers are banked and so we can see that all of the R 13 and are 14 are banked across all of the other modes other than system and user.
And so that way, you don't have Teoh save those along with some of the,
program status registers.
All right, so let's get into a
a very small program here, so we'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 in instead of using E X right, we're going to use our zero seconds 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,
um, accumulator type register.
And then if we type A s for the assembler
and so the input is first start s the output that it's gonna create his 1st 0
Oh, I forgot the minus. So there for output.
And then you can say gcc and minus. Oh, so this is the output for this. So first
and the input that we're going to use his 1st 0
And if we run our program
and then we can say echo, get the result. Unless I in question, Mark.
So you saw on our program we knew moved the number seven in there. And so the return result is seven.
So, additionally, we can create a make file for this.
So to build, all of the targets were going to use. First, there's going to be our main thing. So to build first
we require 1st 0.0
and then with the make value, got to use tab to do the line that you want to do. So GCC
minus Oh first got out
and then to build the first auto object,
the required file or with the changes is first. That s
that a s mine is over 1st 0
for stuff. 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 start out so
So I named my file here first. That out so RM is going to remove
are for recursive that for 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 his first require first requires first thought. Oh, and so this is how to build that. What is first out? Oh,
require first dot over cars first dot s. And so first I'd f changes. Then it'll do this command and then this is modified so that it read 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 then are our file God created. And so now we can run first start out
and if we echo will see that the number seven was there.
All right, so today we gave ah 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 Miller MJ at you and Kate I e to you and you find me on Twitter at Milhouse 30
How to Use GDB (BSWJ)
The GNU Debugger (GDB) is one of the most commonly-used debugging tools in the world. ...
Certificate of Completion Offered
How to Use IDA (BSWJ)
The IDA is used throughout the IT and cybersecurity industries by exploit developers, vulnerability analysts, ...
Certificate of Completion Offered