Indirect Addressing and Variables Part 1

Video Activity
Join over 3 million cybersecurity professionals advancing their career
Sign up with
or

Already have an account? Sign In »

Course
Time
13 hours 15 minutes
Difficulty
Beginner
CEU/CPE
14
Video Transcription
00:01
Hello, This is Dr Miller. This is Episode 6.1 of Assembly.
00:09
Today, we're gonna talk about indirect address ing and variables
00:14
in direct address ing.
00:17
So in direct address, ING is a way that we can point to some memory and we will do this by using things like we've already done before. So, for example,
00:28
Hello, D B. This is a string comma zero.
00:32
So that is allocating some memory in ram that we can then use inside of assembly.
00:39
And again, we've been using it in class. So, for example, moving that value into yea X
00:44
and then calling the print string.
00:47
And so this is how we can define different pieces of data that we can use. And we can also create variables,
00:54
so variables,
00:56
so variables are defined in one of the two sections. We have the BSS, and we have the dot data section,
01:03
so each one of these can have variables within it,
01:06
and so we kind of defined them differently. So in the data section,
01:10
we use the name of the variable and then we say db to define a bite and then zero we give it a value.
01:15
So within the data section. We can actually give things values,
01:21
but in the B s s, we don't actually assign it value
01:25
so we can allocate space in the BSS, but we don't give it an initial value. And so that's the only difference. Why you would want to choose
01:32
the data section or the BSS section is if
01:36
if you want it to have a known value. So, for example, if you wanted to create a buffer where you were going to load in some data, you might use the BSS. But if you had a variable that was a counter or something, you might want to use the data.
01:51
So here we can see some examples of of using these. And so in this 1st 1 when we move into a register the value of our one that's actually copying its address in T a X, and then we're printing that.
02:04
So we're printing the address. So the address is 134520872 right? It's just some random value.
02:12
That's because the OS will give you different values within the system.
02:15
And so here we are. We're printing that image and imprinting a new line.
02:21
But when we say get me the data at
02:23
at the address of variable one, right? So it d references that it'll copy that data in T A X. So that's the value that we gave it. There's the number zero
02:34
and we go ahead and print that in print a new line and we can see that the number zero is printed.
02:38
So one of the big things is knowing. Do you get the address or do you get the value at the address? And so that's the different notation here of using the brackets
02:52
and so we can do it both ways so we can move the value into yea X, and we can do it for at this look of us the address,
03:01
whereas something like this, it will move the bite. And so the very first bite is the letter h
03:08
and so well, move that into a L.
03:12
But there is this notion that we have something called buddy Little Indian, which will talk about later. But the bites are sort of in the reverse order that you might think of them.
03:21
And so here we're actually moving the letters E and H into a X because X is a 16 bit register.
03:29
A L is an eight bit register. E X is a 32 bit register,
03:32
and so here we can either copy eight bits or 16 bits or 32 bits of value from there.
03:40
Normally, we wouldn't be moving strings into a register, but
03:44
but we can get all of the different pieces of data, and then we can do things like take our variable and we can
03:51
add to it if we want to go a different location.
03:55
So here's an example that you might do in a high level language. You might say something like, um, Fred Plus Plus,
04:02
also, what we have to do is we have to load the value in from Fred into a register, and then we can do some operation on it. So we add one to it, and then we can save that data back to the register.
04:15
Right? So this is copying the number 18 back into Fred,
04:18
and so that's how we can. We can load some data to and from memory. And so these air type of operations that you would want to use when you're writing a program.
04:30
So here's another example. And this is based off of the different fact that we have different addresses.
04:36
So we have a string that has car rocket horse,
04:41
and so we can just print that in a normal fashion.
04:44
All right, so we move it into the A X called Prince String Crop print line. Right. That'll print the whole string.
04:48
So we get car rocket horse.
04:53
So if we move the address into the a X and then we add to four to it, we would skip the letter C A r in the space, and salada point to the letter R.
05:02
All right, so we can have these addresses and we can manipulate them. So if we add for to that initial address of string, we will get
05:11
the word rocket horse,
05:13
right?
05:15
And then, if you take it a step further and again, move the address of string into yea X and then at 11. So if you count out, there's 11 characters between the sea and the H,
05:26
and so now it just points to the word horse.
05:30
So we add 11 to that address, right? We're adding to the address on the actual value And then we can call Prince String imprint New Line.
05:36
And so we can see here that it printed off horse as the last one.
05:41
And so we have the ability to manipulate thes addresses if we need to. And so a lot of times, students or programs will allocate one big, long string,
05:51
and then they'll just calculate what the offset is that they need to go to in order to print a particular part of the string.
Up Next
Assembly

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

Instructed By