Hello, this is Dr. Miller, and this
is Episode seven point four of
assembly
today. What we're going to do is
we're going to take a program that
we've already written and we're
going to convert it so that it uses
macro's.
So for this program, it's the same
program that we did earlier,
and when we did it, we used
hardcoded offsets and so we'd
like to do is convert those offsets
to either parameters
or arguments, depending on which one
that they are.
All right, so I've logged on to the
server, and now what I'm going to do
is I've already got the code set up.
Go ahead and load that up.
And I already have the program
loaded that we had started before,
and so what we're gonna do is we're
going to come down here and we're
just going to convert this program
so that it uses the appropriate
macros.
So what we're going to be replacing
is this here.
So the first thing that we have to
do is we have to say push
some sort of context and it's just a
name so that the assembler
knows what we're doing and then we
can set our stack size.
And then we can create a special
variable that the assembler will
use to figure out how many local
variables we have.
And we're just initializing it and
then basically we can tell it what
arguments we have and then what
local variables have so percent
argh!
So NT is the number that
we used in our C program and
then for our locals.
So I'm defining each one of these as
a D word, which means that they take
a four bites.
And then this should allocate the
local size that it defined when
it was looking for each local
variable,
and so in this case, it should be
eight, right.
So we have two D words.
And so it should end up generating
the number eight for that.
And then we'll go down here to the
bottom and then we just got to pop
that context.
So that will remove that context,
that the assembly will work, right,
and then down here, instead of the
epilog, we're going to use leave,
which does the same thing.
So it should fix our stack
appropriately.
Now, when we come into our program,
we need to find every place that we
used a hardcoded offset SBP
minus four, and we
can just use the variable that we've
defined. So this would be some.
This one is I saw
I is minus eight, so I'll go ahead
and find all the places I.
Each one of these will become AI
and then minus four is some.
And then we see you had SBP plus
eight, which is.
And so we can just use and in this
case.
So when you start your program from
scratch, it would be a lot easier to
start with this because then you can
just use variable names instead of
trying to remember the hardcoded
offsets.
So we should be able to build this.
All right.
And we should get the same results
that we got before.
So today, we talked about converting
our program so that it didn't use
hard coded offsets, which are much
more difficult, but
we saw that we had a little bit more
work to do up front and we learned
what that work is and then how we
could do that in an example.
Looking forward, we're going to
start talking about floating point
numbers and how we do operations on
floating point numbers within a
computer,
if you have questions, you can
contact me at millirems,
you Ankita Edu, and you can find me
on Twitter at Millas 30.