Hello, this is Dr. Miller, and this
is Episode six point one of
Assembly.
Today, we're going to talk about
indirect addressing and variables.
Indirect addressing,
so indirect addressing 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,
Deb, 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 yak's
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.
So variables are defined in one of
the two sections, we have the
abscess and we have the data
section, so each one of these
can have variables within it.
And so we kind of define 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 best, we don't actually
assign it a value so
we can allocate space in
the bÃÆsescu. 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 best
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 best.
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 first one, when we move
into a register, the value of our
one, that's actually copying
its address into
X and then we're printing that.
So we're printing the address.
So the addresses one three four or
five two zero eight seven two.
Right. It's just some random value.
And that's because the OS will give
you different values within
the system.
And so here we are.
We're printing that integer and then
printing a new line.
But when we say, get me the data at
at the address, a variable
one. So it dereference
is that it'll copy that data.
And so that's the value
that we gave it,
the number zero.
And then we go ahead and print that
in print and online and we can see
that the number of 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 yak's
and we can do it for right.
This will give us the address,
whereas something like this,
it'll move the bite.
And so the very first bite is the
letter H.
And so we'll move that into A-L.
But there is this notion that we
have something called Lydie Little
Indian, which we'll 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
X because Acts is a 16
bit register.
A L is an eight bit register, X
is a 32 bit register.
And so here we can either copy
eight bits or sixteen bits
or thirty two bits of value
from there.
Now normally we wouldn't be moving
string's 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
Fred plus plus most
of 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 are 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 Rockit horse,
and so we can just print that in a
normal fashion.
Right. So we move it into called
line online. That'll print the whole
string.
So we get car Rockit horse.
So if we move the address into
Yak's and then we add two four
to it, we would skip the letters C,
A, R and the space.
And so that would point to the
letter R, right.
So we can have these addresses and
we can manipulate them.
So if we add four to that initial
address of string, we will
get the word
rocket horse.
Right.
And then if you take it a step
further and again, move the address
of string into X and then at 11,
so if you count out there's 11
characters between the C
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,
not the actual value, and then we
can call print string and print new
line.
And so we can see here that I
printed off course as the last one.
And so we have the ability to
manipulate these 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.