Hello, This is Dr Miller. This is Episode 6.1 of Assembly.
Today, we're gonna talk about indirect address ing and variables
in direct address ing.
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,
Hello, D B. This is a string comma zero.
So that is allocating some memory in ram that we can then use inside of assembly.
And again, we've been using it in class. So, for example, moving that value into yea X
and then calling the print string.
And so this is how we can define different pieces of data that we can use. And we can also create variables,
so variables are defined in one of the two sections. We have the BSS, and we have the dot data section,
so each one of these can have variables within it,
and so we kind of defined them differently. So in the data section,
we use the name of the variable and then we say db to define a bite and then zero we give it a value.
So within the data section. We can actually give things values,
but in the B s s, we don't actually assign it value
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
the data section or the BSS section is if
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.
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.
So we're printing the address. So the address is 134520872 right? It's just some random value.
That's because the OS will give you different values within the system.
And so here we are. We're printing that image and imprinting a new line.
But when we say get me the data at
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
and we go ahead and print that in print a new line and we can see that the number zero is printed.
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
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,
whereas something like this, it will move the bite. And so the very first bite is the letter h
and so well, move that into a L.
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.
And so here we're actually moving the letters E and H into a X because X is a 16 bit register.
A L is an eight bit register. E X is a 32 bit register,
and so here we can either copy eight bits or 16 bits or 32 bits of value from there.
Normally, we wouldn't be moving strings into a register, but
but we can get all of the different pieces of data, and then we can do things like take our variable and we can
add to it if we want to go a different location.
So here's an example that you might do in a high level language. You might say something like, um, Fred Plus Plus,
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.
Right? So this is copying the number 18 back into Fred,
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.
So here's another example. And this is based off of the different fact that we have different addresses.
So we have a string that has car rocket horse,
and so we can just print that in a normal fashion.
All right, so we move it into the A X called Prince String Crop print line. Right. That'll print the whole string.
So we get car rocket horse.
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.
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
the word rocket horse,
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,
and so now it just points to the word horse.
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.
And so we can see here that it printed off horse as the last one.
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,
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.