Assembly

Course
Time
13 hours 15 minutes
Difficulty
Beginner
CEU/CPE
14

Video Transcription

00:00
Hello. This is Dr Miller, and this is Episode 11.1 of Assembly.
00:05
Today we're gonna talk about the arm architecture,
00:08
the arm architecture.
00:10
So arm originally stood for the Acorn RISC machine or later, the Advanced RISC machine.
00:17
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.
00:37
But if you look at the arm design, we actually have less transistors. So we
00:42
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
00:54
and tablets are going to run arm,
00:57
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.
01:03
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,
01:15
and then they sell these two manufacturers and fabrication plants.
01:19
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.
01:36
And then, in a future lecture will talk about the template and a make file in project folders,
01:41
and then we'll use the canoe assemblies in tax. So this will be different than Moazzam. Better to all be related to,
01:48
um, the arm architecture.
01:51
And then probably the easiest to use is using a raspberry pi with raspy and installed.
01:56
And so, for these lectures, I will log on to a raspberry pied machine, and we will use that to create our code.
02:06
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.
02:21
And so this is called the Link Register or L R.
02:24
And then when we talk about returning
02:27
or branching, it's the be so branch. With Link, the Link register will
02:32
jump to the new location and then set the link register to where we were we came from.
02:38
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,
02:47
Um, and then we'll have an example here that we're in and type in in a little bit.
02:53
So one of the other differences is the arm includes a whole bunch of system modes that you can use
03:00
and so we can see that we have things like the fast interrupt Q or F I. Q.
03:05
So that is a fast way to interrupt the processor we have General Interrupts or the I R. Q.
03:10
We have a supervisor mode, and this allows protected mode, which has some instructions you can't execute.
03:17
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,
03:28
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
03:44
and then for registers, we're gonna have 16. Registers are zero through. Our 15
03:50
are zero is going to be our accumulator register are 13 will typically see used as SP for Stack Pointer
03:58
are 14 is our link register.
04:00
AR 15 is a program Canada or instruction pointer that we've looked at in X 86
04:08
and again you can use these short hands spl, RPC.
04:12
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.
04:20
And then we have the current process Status register. CPS are
04:26
so this is 32 bits, and it basically holds all of the flags that we have in our program.
04:31
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
04:46
and then Arm has several different operating states. Of the typical operating state is the 32 bit word aligned instructions.
04:54
And so that's just what we call our moon
04:57
now. They also have a 16 bit instructions. So here each of the the instructions is 32 bits
05:03
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
05:14
accessible to us,
05:15
Um, and that way we cannot use them. So sometimes you have to go back and forth between our mode and thumb bone.
05:23
And then
05:24
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
05:32
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.
05:47
Where his arm. Every instruction is the exact same with depending on if it's an arm with a moon
05:55
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.
06:04
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.
06:15
But we can access different pieces of data depending on which Modry in.
06:20
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.
06:35
And so, for example, the fast interrupt Que has seven banked registers,
06:41
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
06:57
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.
07:14
And so that way, you don't have Teoh save those along with some of the,
07:18
um,
07:19
program status registers.
07:23
All right, so let's get into a
07:25
a very small program here, so we'll go ahead and try and take this in.
07:34
So we're going to start off. We're going to create a program called First
07:40
s for Assembly. Don't know why that that is.
07:53
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
08:01
and we'll talk about numbers. The number seven
08:07
branch exchange with the link register.
08:09
So again, this is going to this part is the return from our function
08:15
and this is just moving a return result into the,
08:18
um, accumulator type register.
08:26
And then if we type A s for the assembler
08:31
and so the input is first start s the output that it's gonna create his 1st 0
08:41
Oh, I forgot the minus. So there for output.
08:45
And then you can say gcc and minus. Oh, so this is the output for this. So first
08:50
dot Out
08:52
and the input that we're going to use his 1st 0
08:56
And if we run our program
09:01
and then we can say echo, get the result. Unless I in question, Mark.
09:05
So you saw on our program we knew moved the number seven in there. And so the return result is seven.
09:13
So, additionally, we can create a make file for this.
09:22
So to build, all of the targets were going to use. First, there's going to be our main thing. So to build first
09:31
we require 1st 0.0
09:35
and then with the make value, got to use tab to do the line that you want to do. So GCC
09:39
minus Oh first got out
09:46
and then to build the first auto object,
09:54
the required file or with the changes is first. That s
10:00
that a s mine is over 1st 0
10:05
for stuff. Yes,
10:07
and then clean is to clean things up if we want to just build it from the scratch.
10:11
And this is
10:13
I'm going to use first start out so
10:16
clean.
10:26
So I named my file here first. That out so RM is going to remove
10:31
are for recursive that for force Remove these two files if we try and do a clean
10:37
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,
10:46
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
11:01
and we'll go ahead and clean.
11:07
So see we when we build. Did make then are our file God created. And so now we can run first start out
11:15
and if we echo will see that the number seven was there.
11:22
All right, so today we gave ah really brief introduction into the arm architecture and arm assembly.
11:28
Looking forward, we're going to set up and use the template that is created for arm.
11:35
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

Up Next

Assembly

This course will provide background and information related to programming in assembly. Assembly is the lowest level programming language which is useful in reverse engineering and malware analysis.

Instructed By

Instructor Profile Image
Matthew Miller
Assistant Professor at the University of Nebraska at Kearney
Instructor