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.8 of Assembly.
00:05
Today, we're going to give an example using the stack and how to save registers.
00:11
So our Stack example.
00:13
So the problem that we've previous really solved is we wanted to write a function that would print off some numbers.
00:21
So we read end from the user, and then we'd print powers of two.
00:25
And so we're take a look at the previous example. And so what we're gonna do is we're gonna right a little function here that goes ahead and prince these off, and we're going to sort of switch some of these registers around so that there,
00:37
um, it makes a little bit more sense and is a little bit easier to understand.
00:42
So let's go there.
00:46
All right, So we have our previous example.
00:50
And so what we'd like to do is we're gonna change up these registers a little bit. So instead of using, um,
00:57
are nine for our constant we're going to use
01:02
This is our one.
01:03
And then our counter value is gonna be in r zero.
01:11
Let's put that in here.
01:18
And then, um, sorry. That's the max
01:23
max values and
01:25
are zero, and then our counter is going to be
01:33
are to
01:44
okay.
01:48
And thus if we write a function that is going to overwrite thes values, we're gonna want to save them. So we're going to create our own function down here called Print.
01:57
And so basically inside of print, we're going to, um, use different registers.
02:04
So, for example, we're going to move
02:07
from our to tow our three. So are three is going to
02:14
have our last argument?
02:15
Um,
02:17
currently. So we're just gonna copy that into our to
02:21
will also move.
02:23
Um,
02:25
this, like this are one gets are too.
02:30
And then load register are zero is going to
02:36
get the format that we want a print
02:40
and then here will go ahead and call print off.
02:45
And we have all of our registers at the end. Very. Instead of return, we got branch and exchange our link register.
02:53
So what we need to do in here is we need to save our registers, so push our
03:00
well all the registers that we're going to use. So we end up using our
03:05
zero through
03:07
or three.
03:09
We're also going to use the link register,
03:13
so you can see we have a branch with links. So that's going to destroy the link register, which has where print function is going to be.
03:19
And so we need to save that. And then at the end, we'll do pop
03:23
R zero to R three
03:28
and the link register.
03:32
So that should be our function that we're going to use to print. Um, here, we're going to change up our registers. So here, we're going to compare our to
03:43
and are zero.
03:46
When we are done, we'll go there,
03:49
um, in here, we're gonna use move into our three is going to get our
03:53
value that we want to print are one.
03:58
And then we will,
04:00
um, do the shift on our to
04:02
here.
04:04
Now, the stuff in here, we're going to, um,
04:10
get rid of because we're not gonna be printing anymore.
04:14
We will print in our new function. So they brand with link to our print function, which we've defined down here
04:20
and then
04:21
instead of our seven we're using, are too.
04:25
So I wanted to use
04:26
are 01 and two inside of here so that we saw that we needed to save those because those are going to get obliterated
04:33
by the print A function,
04:38
and we'll take out some additional space
04:41
Double check here. So our to our one. Okay,
04:50
so we can see that we print off three powers of two or six powers of two or someone and so forth.
05:01
So today we looked at creating your own function and making sure that we saved the appropriate registers. So the ones that were using inside of our function that could be modified as well. As if you're calling a function with branch and link, you saved the link register.
05:16
So, looking forward, we're going to talk about arm indexing and possibly armor raise.
05:21
If you have questions, you can email me Miller, MJ, you and Kate. I e d u. And you can 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