ARM Math and Data Movement

Video Activity
Join over 3 million cybersecurity professionals advancing their career
Sign up with
Required fields are marked with an *
or

Already have an account? Sign In »

Course
Difficulty
Beginner
Video Transcription
00:01
Hello. This is Dr Miller, and this is Episode 11.3 of Assembly.
00:05
Today, we're gonna discuss some of the arm basics, and this will include math operations and then the movement of data.
00:12
So our math.
00:14
So from the arm docks, we basically have an operator that we have. And then we can have several different
00:21
registers that we can use so we can have a destination register a source register, and then another operandi.
00:28
And then we can also have a an immediate value. And so some of that it for math operations. We can do our ad ad with Kerry. Subtract,
00:38
reverse, subtract superior, tracked with Carrie and reverse attract with Carrie. So typically,
00:44
um, from this, you'll end up using add or subtract, or the basic ones that you'll end up using
00:52
and then armed data movement.
00:54
So when we move data, we can use M. O V.
00:58
And so this will copy into a registered the operandi. We want to move into it. So that might be another register.
01:04
So here we can see Move R one R zero so r zero gets copied into our one.
01:11
Ah, we can use, um
01:15
move rd so destination some immediate value until that's just a
01:19
a number that we can move in there. So we moved the number 32 into our nine. So probably one of the biggest things that catches most of my students is just forgetting the, um
01:33
Either some kids call it hashtag or others called the Octo Thorpe or,
01:37
um, bang hash
01:40
is another name for it.
01:42
And then we also have em the end. So move and invert. So it will basically,
01:49
um, take the number two here and inverted, and so turn it into negative to moving that into our one.
01:57
Um And then we're allowed to basically move into a different destination than the source with the different move operations.
02:07
So again, here's another example.
02:08
So here we can move the number 103 into our zero move. The number 44 toe are one,
02:15
and then with our ads. So we end up using our zero. But we could use a different registered refugees are too. But in this example, we're using our zero so r zero gets the value of
02:27
are zero post are ones. I take ours there on our one Add them together and then store the result in R zero.
02:35
And then when we're done, we can say branch with link to print int. So I don't print off the number that we have done by adding those two together.
02:43
And then we can see that we have a push in a pop of the Link Register, which we saw in the previous see lecture.
02:50
And then we're all done. We can do branch exchange at the Link Register in order to exit our program.
03:00
So additionally, we can load data from memory. And so one of the differences in when we talked about x 86
03:08
we had the ability to say move and the move command would either move from memory
03:14
or it would move from a register. And so when you're dealing with arm, basically they have separate
03:22
commands that will load a register from RAM or memory.
03:28
And so we have two different commands for loading from from memory while loading from memories. LD R Load register
03:36
and str is store register.
03:38
So listen a load data from a register from memory into a register in this will store memory from register into memory,
03:47
and so if you look again the armed docks, they have a lot of different of these. And we're going to go through the pre index and post index,
03:55
um, later on. But basically we have an operation which could be load or store.
04:01
Um and then this is double wide and so we can use this to do it. And so for operation, it's either load or store.
04:11
RT is the registered to loader store, Um and then rt to is if we have a double word. So we have to have twice a much space.
04:20
We can add an offset, and we'll talk about that when we talk about a raise. And then we got bites, signed, bites half words and signed half words.
04:30
And again, that's a lot of documentation. But that's what is on the arm site. So what kind of break it down a little bit easier. So,
04:39
for example, if I want to get the address of X
04:44
so I can use load
04:46
registered to load the address of X into our one
04:49
and then I can say load, register and get the value at our ones are one is an address, and again I'm taking the value at that location and storing it here.
04:59
So this had the address of our variable. And now when I say that it's going to have the value from our register.
05:05
And so any time you're going to load something from memory, you basically need this two step process.
05:12
Um, when we're dealing with arm
05:15
and then here we can see we're doing an ad. And again we have our destination is different than these. So add,
05:20
um, we're gonna get R one plus R to add those together and store that in or zero
05:28
and then we're done. We can do a branch of link to print into and print the result.
05:33
Um, and then we're done. We can do a pop and, um, return from our program. So let's try toe quickly and put this program.
06:00
So here's our data section.
06:06
Tell it to align to four by boundaries. The variable X is a word
06:13
has the number 35
06:16
all right?
06:19
It will declare our variables and our functions
06:26
So print
06:30
and then
06:31
is our function main.
06:35
So here,
06:38
get rid of that.
06:40
So go ahead and push our
06:45
link register.
06:46
But the end will pop
06:49
our link register.
06:57
We'll get the address of X
07:02
and then get the value of the data pointed to buy X.
07:13
Make sure you put the HASHTAG in front of here,
07:24
Then call our function print int.
07:31
So it takes 35 adds seven to it and we end up with the number 42
07:39
all right today. Today we talked about the math operations, and then we talked about the basic arm data movement
07:46
to and from registers and tune from memory.
07:49
So in the future, we'll talk about arm indexing modes and the ability to use that with a raise and then arm brain Jing.
07:58
So how do you load a register from my memory address
08:01
We use LD R.
08:05
And then how do we add R one and R two and save it in our three
08:11
add R three, R one and r two. The order really doesn't matter.
08:16
So if you have questions, you can email me Miller MJ at you and Kate I e d u. And you can find me on Twitter at No House 30
Up Next
Branching, If, While, Shift
Shift Example
Memory, Offsets, Debugging and Listing
Pushing and Popping
Push Example