WEBVTT

00:03.260 --> 00:04.759
Hello, this is Dr. Miller, and this

00:04.760 --> 00:06.379
is Episode seven point four of

00:06.380 --> 00:07.380
assembly

00:08.390 --> 00:09.499
today. What we're going to do is

00:09.500 --> 00:10.639
we're going to take a program that

00:10.640 --> 00:11.839
we've already written and we're

00:11.840 --> 00:13.369
going to convert it so that it uses

00:13.370 --> 00:14.370
macro's.

00:16.120 --> 00:17.949
So for this program, it's the same

00:17.950 --> 00:19.379
program that we did earlier,

00:19.900 --> 00:21.489
and when we did it, we used

00:21.490 --> 00:23.379
hardcoded offsets and so we'd

00:23.380 --> 00:25.239
like to do is convert those offsets

00:25.240 --> 00:26.240
to either parameters

00:27.100 --> 00:28.899
or arguments, depending on which one

00:28.900 --> 00:29.900
that they are.

00:42.830 --> 00:44.179
All right, so I've logged on to the

00:44.180 --> 00:45.829
server, and now what I'm going to do

00:45.830 --> 00:47.360
is I've already got the code set up.

00:51.610 --> 00:53.219
Go ahead and load that up.

00:58.510 --> 00:59.709
And I already have the program

00:59.710 --> 01:01.350
loaded that we had started before,

01:02.200 --> 01:03.369
and so what we're gonna do is we're

01:03.370 --> 01:04.479
going to come down here and we're

01:04.480 --> 01:05.859
just going to convert this program

01:05.860 --> 01:08.319
so that it uses the appropriate

01:08.320 --> 01:09.320
macros.

01:10.570 --> 01:12.130
So what we're going to be replacing

01:12.790 --> 01:14.980
is this here.

01:19.460 --> 01:20.569
So the first thing that we have to

01:20.570 --> 01:22.189
do is we have to say push

01:22.490 --> 01:24.109
some sort of context and it's just a

01:24.110 --> 01:25.384
name so that the assembler

01:26.030 --> 01:27.696
knows what we're doing and then we

01:27.890 --> 01:30.200
can set our stack size.

01:34.100 --> 01:35.668
And then we can create a special

01:35.900 --> 01:37.819
variable that the assembler will

01:37.820 --> 01:39.139
use to figure out how many local

01:39.140 --> 01:40.140
variables we have.

01:47.850 --> 01:49.739
And we're just initializing it and

01:49.740 --> 01:51.179
then basically we can tell it what

01:51.180 --> 01:52.679
arguments we have and then what

01:52.680 --> 01:54.430
local variables have so percent

01:54.540 --> 01:55.540
argh!

01:58.050 --> 01:59.226
So NT is the number that

01:59.940 --> 02:01.859
we used in our C program and

02:01.860 --> 02:02.939
then for our locals.

02:13.890 --> 02:15.359
So I'm defining each one of these as

02:15.360 --> 02:16.709
a D word, which means that they take

02:16.710 --> 02:17.710
a four bites.

02:30.050 --> 02:31.667
And then this should allocate the

02:32.150 --> 02:33.669
local size that it defined when

02:34.100 --> 02:35.719
it was looking for each local

02:35.720 --> 02:36.720
variable,

02:38.360 --> 02:39.859
and so in this case, it should be

02:39.860 --> 02:40.689
eight, right.

02:40.690 --> 02:42.169
So we have two D words.

02:42.170 --> 02:43.879
And so it should end up generating

02:43.880 --> 02:44.960
the number eight for that.

02:45.620 --> 02:46.579
And then we'll go down here to the

02:46.580 --> 02:48.246
bottom and then we just got to pop

02:48.560 --> 02:49.560
that context.

02:52.050 --> 02:53.540
So that will remove that context,

02:53.580 --> 02:55.259
that the assembly will work, right,

02:55.530 --> 02:57.179
and then down here, instead of the

02:57.180 --> 02:59.309
epilog, we're going to use leave,

03:00.930 --> 03:02.219
which does the same thing.

03:03.810 --> 03:04.949
So it should fix our stack

03:04.950 --> 03:05.950
appropriately.

03:06.780 --> 03:08.429
Now, when we come into our program,

03:08.430 --> 03:10.109
we need to find every place that we

03:10.110 --> 03:12.539
used a hardcoded offset SBP

03:12.570 --> 03:13.570
minus four, and we

03:14.520 --> 03:16.109
can just use the variable that we've

03:16.110 --> 03:17.999
defined. So this would be some.

03:19.170 --> 03:20.170
This one is I saw

03:21.210 --> 03:22.799
I is minus eight, so I'll go ahead

03:22.800 --> 03:24.479
and find all the places I.

03:29.060 --> 03:31.299
Each one of these will become AI

03:31.310 --> 03:33.289
and then minus four is some.

03:44.710 --> 03:46.278
And then we see you had SBP plus

03:46.810 --> 03:47.810
eight, which is.

03:47.860 --> 03:49.526
And so we can just use and in this

03:49.840 --> 03:50.840
case.

03:52.900 --> 03:54.309
So when you start your program from

03:54.310 --> 03:55.959
scratch, it would be a lot easier to

03:55.960 --> 03:57.339
start with this because then you can

03:57.340 --> 03:58.989
just use variable names instead of

03:58.990 --> 04:00.669
trying to remember the hardcoded

04:00.670 --> 04:01.670
offsets.

04:03.010 --> 04:04.539
So we should be able to build this.

04:08.960 --> 04:09.960
All right.

04:12.670 --> 04:15.160
And we should get the same results

04:15.190 --> 04:16.269
that we got before.

04:20.750 --> 04:22.514
So today, we talked about converting

04:22.790 --> 04:24.529
our program so that it didn't use

04:24.530 --> 04:26.209
hard coded offsets, which are much

04:26.210 --> 04:28.010
more difficult, but

04:28.040 --> 04:29.804
we saw that we had a little bit more

04:29.810 --> 04:31.476
work to do up front and we learned

04:31.910 --> 04:33.527
what that work is and then how we

04:33.680 --> 04:35.629
could do that in an example.

04:37.340 --> 04:38.389
Looking forward, we're going to

04:38.390 --> 04:40.056
start talking about floating point

04:40.070 --> 04:41.899
numbers and how we do operations on

04:41.900 --> 04:43.279
floating point numbers within a

04:43.280 --> 04:44.280
computer,

04:45.200 --> 04:46.309
if you have questions, you can

04:46.310 --> 04:48.270
contact me at millirems,

04:48.490 --> 04:50.205
you Ankita Edu, and you can find me

04:50.300 --> 04:51.889
on Twitter at Millas 30.

