WEBVTT

00:00.750 --> 00:02.249
Hello, this is Dr. Miller, and this

00:02.250 --> 00:03.599
is Episode nine point one of

00:03.600 --> 00:05.519
assembly today we're

00:05.520 --> 00:06.869
going to give an example of how to

00:06.870 --> 00:08.849
do a three no,

00:08.850 --> 00:09.850
Max.

00:10.860 --> 00:12.329
So for this example, what we're

00:12.330 --> 00:13.259
going to do is we're going to

00:13.260 --> 00:14.969
calculate the max of three numbers,

00:15.540 --> 00:16.919
will read the three numbers in

00:16.920 --> 00:18.449
Bioscan F, and we'll

00:19.020 --> 00:20.670
get introduced to using an array

00:21.360 --> 00:22.889
and then we're going to return the

00:22.890 --> 00:24.629
result in X and we're going to try

00:24.630 --> 00:26.519
and use some local variables for

00:26.520 --> 00:27.520
our program.

00:28.560 --> 00:30.239
So I've already created my project

00:30.240 --> 00:31.240
here.

00:33.980 --> 00:34.980
So

00:36.290 --> 00:37.699
in order to make our life easier,

00:37.700 --> 00:38.979
we're going to use some percent

00:39.020 --> 00:40.849
defines in order to define the

00:40.850 --> 00:41.989
variables that we're going to use

00:41.990 --> 00:43.109
inside of our function.

00:44.270 --> 00:45.350
So percent.

00:49.220 --> 00:50.990
So do fine.

00:51.700 --> 00:53.349
And we're going to call this in one

00:54.460 --> 00:56.169
SBP plus eight,

00:56.500 --> 00:58.240
so that'll be our first argument

00:58.360 --> 00:59.529
and we'll do the same for the next

00:59.530 --> 01:00.530
two.

01:08.650 --> 01:10.022
I do zero, see, because it's

01:10.480 --> 01:12.440
a letter, and so you've got to start

01:12.460 --> 01:13.659
with a zero if it's going to be in

01:13.660 --> 01:14.660
Hex

01:15.910 --> 01:17.319
and then three

01:17.830 --> 01:19.600
is going to be BP

01:20.080 --> 01:21.340
plus 10 hex.

01:22.030 --> 01:23.500
So we got eight, 12

01:24.100 --> 01:26.379
and 16 or

01:26.500 --> 01:27.939
eight, C and 10.

01:29.050 --> 01:30.219
And then here we're going to define

01:30.220 --> 01:31.809
what our SCANA format is.

01:36.620 --> 01:37.759
And we're just going to basically

01:37.760 --> 01:39.979
allow it to scan in three

01:40.280 --> 01:41.280
integers.

01:43.210 --> 01:44.629
Got to make sure we will terminate

01:44.630 --> 01:45.630
it.

01:46.970 --> 01:49.099
And then down here in the best,

01:49.100 --> 01:50.420
we're going to find an array.

01:53.210 --> 01:55.730
So the rest means reserve,

01:55.850 --> 01:57.516
D means D word, and so we're going

01:57.680 --> 01:59.270
to reserve three D words

02:00.110 --> 02:01.889
and we're going to be using ganef.

02:01.910 --> 02:03.799
And so we got to say that that's

02:03.800 --> 02:04.800
extern.

02:09.250 --> 02:11.169
All right, so in

02:11.170 --> 02:12.170
order to

02:13.240 --> 02:14.859
scan these in, we basically have to

02:14.860 --> 02:16.809
give it three different addresses

02:16.810 --> 02:18.759
that we want to use to store

02:18.760 --> 02:19.760
our numbers.

02:20.290 --> 02:21.290
And so

02:23.140 --> 02:24.309
the first one that we're going to

02:24.310 --> 02:26.319
use is we're going to basically load

02:26.320 --> 02:27.639
the address of the array

02:28.750 --> 02:30.159
and we'll just push that onto the

02:30.160 --> 02:31.809
stack. So this is a pointer to that

02:31.810 --> 02:33.039
location in memory.

02:34.330 --> 02:36.189
Now, the

02:36.310 --> 02:37.809
each one of these D words takes up

02:37.810 --> 02:39.669
four bytes. So to the address, the

02:39.670 --> 02:41.139
next one, we're going to add four

02:41.140 --> 02:41.919
bytes.

02:41.920 --> 02:44.159
So add X

02:44.320 --> 02:45.320
for.

02:52.780 --> 02:54.819
So here we get the base address

02:57.880 --> 02:59.889
and then we'll go ahead and push

02:59.890 --> 03:01.300
that address onto the stack

03:02.050 --> 03:03.550
and then we can add again

03:04.630 --> 03:06.247
another four to point to the next

03:06.550 --> 03:07.550
one.

03:10.380 --> 03:12.629
So we added four, added four more,

03:13.680 --> 03:15.329
and we'll push that pointer onto the

03:15.330 --> 03:16.330
stack and

03:17.190 --> 03:18.539
then we got to push our format.

03:23.140 --> 03:24.580
And then we're going to call

03:25.450 --> 03:26.450
Scantest

03:28.060 --> 03:29.289
and then we've got to make sure that

03:29.290 --> 03:30.419
we correct the stack.

03:30.430 --> 03:31.430
So if we count all

03:32.470 --> 03:34.179
of the things that we added on here,

03:34.180 --> 03:36.009
that is 14

03:36.010 --> 03:38.500
Hecks. So we've got four,

03:38.530 --> 03:40.419
eight, 12.

03:41.950 --> 03:43.900
And then 16, I

03:43.950 --> 03:45.520
see, did I push them all on?

03:48.100 --> 03:50.020
OK, so we should

03:50.030 --> 03:51.030
add.

03:56.200 --> 03:57.200
Looks like 10.

03:58.680 --> 04:00.620
Oh, go with that.

04:02.120 --> 04:03.120
All right.

04:03.200 --> 04:05.089
And now we want to

04:06.020 --> 04:07.441
go ahead and push those items

04:08.330 --> 04:10.219
onto our stack so

04:10.670 --> 04:12.709
we can move in to the values,

04:12.710 --> 04:13.999
store that array,

04:16.190 --> 04:17.629
and then we can push that onto the

04:17.630 --> 04:18.630
stack.

04:19.890 --> 04:22.329
And then we can move into X

04:23.310 --> 04:25.829
the value of Arae

04:26.130 --> 04:27.240
plus four

04:28.110 --> 04:29.310
and push that value.

04:29.520 --> 04:31.529
So these are D referencing that

04:31.530 --> 04:33.509
pointer and then getting us

04:33.510 --> 04:34.510
the value.

04:34.770 --> 04:35.879
So those are the numbers that we

04:35.880 --> 04:37.769
read via the keyboard and then

04:37.770 --> 04:39.360
do the last one. You've

04:40.040 --> 04:41.249
got x

04:41.940 --> 04:44.189
ray plus eight.

04:48.700 --> 04:49.629
And then we're going to call our

04:49.630 --> 04:50.949
function to call

04:52.240 --> 04:53.240
Max three

04:54.250 --> 04:55.818
is going to be the name and then

04:56.110 --> 04:57.489
we'll go ahead and again correct our

04:57.490 --> 05:00.009
stack and

05:01.720 --> 05:02.779
E.S.P.

05:05.070 --> 05:06.491
And then the result should be

05:06.960 --> 05:09.209
an X, so we're just going to call

05:10.240 --> 05:11.240
Sprint and and

05:12.120 --> 05:13.120
call

05:14.340 --> 05:16.109
brand new line.

05:17.730 --> 05:19.347
So now we've got to go and create

05:19.410 --> 05:21.125
our function that we're going to do

05:21.210 --> 05:23.250
the max of three numbers.

05:26.440 --> 05:28.269
So we're going to call this Max

05:28.600 --> 05:29.600
three.

05:32.370 --> 05:34.085
Go ahead and enter our function and

05:34.350 --> 05:35.639
allocate some space.

05:37.350 --> 05:38.910
We're going to save our registers.

05:45.120 --> 05:46.198
OK, we're not going to

05:46.980 --> 05:48.479
push X because we're actually going

05:48.480 --> 05:49.979
to use that in our function at the

05:49.980 --> 05:51.449
end of our function, we're going to

05:51.450 --> 05:53.420
go ahead and say Pop,

05:53.450 --> 05:55.560
MDX, Pop,

05:56.060 --> 05:57.569
DCX,

05:58.800 --> 06:00.179
Pop to

06:00.810 --> 06:01.889
be X

06:02.700 --> 06:04.379
and then we'll use leave

06:04.650 --> 06:05.789
because we can

06:08.440 --> 06:09.440
I can type and

06:10.500 --> 06:11.669
then do our return.

06:14.480 --> 06:16.500
So here say

06:16.680 --> 06:17.850
registers.

06:27.420 --> 06:29.100
And here, this is going to be the

06:29.670 --> 06:30.810
end of our Loopt.

06:32.130 --> 06:33.899
OK, our end of our function,

06:33.900 --> 06:34.900
actually,

06:35.820 --> 06:37.584
so what we want to do is we're going

06:37.710 --> 06:39.389
to use those percent defines that we

06:39.390 --> 06:41.007
define. So we could type this all

06:41.160 --> 06:42.679
out and say EBP plus eight, but

06:43.200 --> 06:44.519
it's probably just easier to set

06:44.520 --> 06:46.050
this up and then

06:46.620 --> 06:47.909
go ahead and load that into a

06:47.910 --> 06:49.625
register. So I'm going to move into

06:49.860 --> 06:51.369
X one.

06:52.020 --> 06:53.609
Now, this is going to replace that

06:53.610 --> 06:54.899
with SBP.

06:59.830 --> 07:00.830
Policy Doublecheck

07:02.110 --> 07:03.110
SBP

07:04.690 --> 07:06.970
plus eight for the first parameter,

07:08.410 --> 07:09.410
so that's what it's going to get

07:09.430 --> 07:10.720
actually replaced with,

07:11.620 --> 07:13.286
but it's a lot easier to type just

07:13.570 --> 07:15.220
these instead of trying to

07:15.970 --> 07:17.060
remember what that is.

07:17.860 --> 07:19.480
So move SBX

07:20.440 --> 07:21.440
to move

07:22.450 --> 07:23.450
DCX

07:24.340 --> 07:25.340
three.

07:25.650 --> 07:27.159
So now we have inside of our three

07:27.160 --> 07:28.483
registers the three numbers

07:29.350 --> 07:31.599
that they entered and we got bioscan

07:31.600 --> 07:33.310
eugh. And so now we're going to do.

07:38.970 --> 07:39.999
Do our comparison, so

07:40.980 --> 07:42.839
we'll do go ahead and compare

07:43.230 --> 07:45.120
the CBX

07:46.260 --> 07:47.850
and then jump above

07:48.390 --> 07:50.459
and I'll just pick a label, a one.

07:51.630 --> 07:53.099
So this is

07:53.700 --> 07:55.829
yak's is bigger.

07:56.760 --> 07:58.339
Take the jump.

07:59.550 --> 08:01.439
OK, and then we'll define

08:01.440 --> 08:02.440
a one here.

08:03.420 --> 08:04.939
So he is bigger.

08:04.950 --> 08:06.540
We're going to move into.

08:08.910 --> 08:10.560
Our maximum, which

08:10.810 --> 08:12.689
let's see if we need to add

08:12.690 --> 08:13.690
that as a

08:14.790 --> 08:15.790
percent define.

08:16.980 --> 08:18.089
So this is going to be a local

08:18.090 --> 08:19.090
variable

08:21.150 --> 08:23.339
and it's going to be SBP

08:23.520 --> 08:24.790
minus eight.

08:25.950 --> 08:27.319
So go ahead and go down.

08:27.780 --> 08:28.829
We'll go down for

08:29.760 --> 08:31.289
it. Should be what we need to go for

08:31.290 --> 08:32.290
it.

08:33.789 --> 08:35.859
OK, so

08:35.860 --> 08:38.259
we'll do a comparison of X and SBX,

08:38.260 --> 08:39.969
and then if that's true, we're going

08:39.970 --> 08:42.039
to move. So if X is bigger,

08:42.070 --> 08:43.149
then we're going to move

08:43.900 --> 08:45.520
into Max.

08:51.310 --> 08:52.310
Yikes.

08:53.230 --> 08:54.279
All right, and then we're going to

08:54.280 --> 08:55.449
jump to the second part, so we're

08:55.450 --> 08:56.769
going to do another comparison.

09:03.850 --> 09:05.799
OK, so

09:05.800 --> 09:07.719
if Vioxx is not bigger, that

09:07.720 --> 09:09.719
means SBX is bigger,

09:09.730 --> 09:11.580
so we're going to move into

09:11.590 --> 09:13.299
max Vioxx

09:14.290 --> 09:16.119
and then here we'll also jump to

09:16.120 --> 09:17.559
part two.

09:19.060 --> 09:20.230
So now here is part

09:21.580 --> 09:22.580
two.

09:23.440 --> 09:25.370
So now we've compared yak's

09:25.390 --> 09:27.429
and SBX and we've saved into

09:27.430 --> 09:29.139
Max, the one that is bigger.

09:30.310 --> 09:31.339
And so what we can do

09:32.140 --> 09:34.409
is we can load into yak's

09:34.510 --> 09:36.369
the bigger one, which is whatever is

09:36.370 --> 09:38.590
stored at Max,

09:38.930 --> 09:41.529
and then we can do a compare Vioxx

09:41.530 --> 09:42.649
and DCX.

09:43.720 --> 09:45.909
So again, jump above,

09:46.630 --> 09:47.889
I'll call it B one.

09:50.650 --> 09:52.419
So instead of B one,

09:53.200 --> 09:55.199
we'll use X as our bigger thing.

09:55.210 --> 09:56.649
Some move into

09:58.000 --> 09:59.739
max eaa x

10:00.400 --> 10:02.289
shown to done

10:03.610 --> 10:04.610
so X is

10:05.740 --> 10:06.740
bigger.

10:07.060 --> 10:08.619
Take the jump.

10:10.750 --> 10:12.039
So if it's not bigger than we need

10:12.040 --> 10:14.470
to move DCX.

10:16.110 --> 10:18.870
Move into Max DCX

10:19.860 --> 10:21.575
because now it's bigger and then we

10:21.600 --> 10:23.039
need to make sure we do our jumps so

10:23.040 --> 10:24.040
that we don't

10:25.260 --> 10:27.029
run the next branch, so we have to

10:27.030 --> 10:28.950
say jump down.

10:31.990 --> 10:32.990
All right,

10:34.120 --> 10:35.443
and then inside, done well,

10:36.190 --> 10:37.479
I guess I called it done, I should

10:37.480 --> 10:38.480
call it done here.

10:39.130 --> 10:40.130
Here we go.

10:42.910 --> 10:44.319
So what we're going to do is move

10:44.320 --> 10:46.900
into Yak's Max.

10:46.930 --> 10:48.549
So, again, that's our local variable

10:49.060 --> 10:51.249
and it has the maximum that we have.

10:51.250 --> 10:52.389
And so we're just going to copy it

10:52.390 --> 10:54.309
from our local variable into the

10:54.820 --> 10:56.799
result that we have for our

10:56.800 --> 10:57.800
function.

11:00.090 --> 11:01.315
And now everything should

11:02.130 --> 11:03.845
be all set up appropriately so that

11:04.080 --> 11:05.570
it works.

11:07.960 --> 11:08.960
We'll see.

11:09.070 --> 11:10.719
Looks like it didn't

11:10.960 --> 11:12.340
fail in the compilation,

11:13.550 --> 11:15.999
if I type numbers one, two, three

11:17.230 --> 11:19.360
or three to one

11:20.380 --> 11:23.180
or one, three,

11:23.270 --> 11:24.460
three, four, two.

11:26.800 --> 11:28.540
And another way to run this, if you

11:28.690 --> 11:29.919
don't want to do that, you can do

11:29.920 --> 11:30.920
echo.

11:33.360 --> 11:34.739
One to

11:35.190 --> 11:36.190
hundred,

11:37.050 --> 11:38.819
and then you can send that output

11:39.180 --> 11:41.309
of the Echo command into the running

11:41.310 --> 11:43.169
this command, so it'd be like I

11:43.170 --> 11:44.819
typed it into the keyboard,

11:46.200 --> 11:47.309
but I don't have to

11:48.090 --> 11:49.320
type it continuously.

11:50.400 --> 11:51.599
So it's just another way that you

11:51.600 --> 11:53.159
can you can run your test.

11:57.360 --> 11:58.977
So today we showed a sort of more

11:59.130 --> 12:01.019
complicated function example, we use

12:01.020 --> 12:02.850
some local variables, we use

12:03.360 --> 12:05.190
three parameters for this example,

12:05.610 --> 12:07.109
and we were able to compute the

12:07.110 --> 12:09.059
maximum of three different numbers

12:09.060 --> 12:10.559
that were inputted by the user.

12:12.170 --> 12:13.169
So in the future, we're going to

12:13.170 --> 12:14.999
talk about conditional

12:15.000 --> 12:16.715
execution or the notion that we can

12:17.070 --> 12:19.290
maybe not use jumps in order to

12:19.650 --> 12:20.990
do some of those operations.

12:21.000 --> 12:22.889
We'll talk about a raise and

12:22.890 --> 12:24.262
then some strings and string

12:24.360 --> 12:25.889
operations that are associated with

12:25.890 --> 12:26.890
them.

12:27.650 --> 12:29.059
If you have questions, you can email

12:29.060 --> 12:31.309
me Milgrim, Jet, you, Ankita, Aidoo,

12:31.310 --> 12:32.740
or you can find me on Twitter at

12:32.760 --> 12:33.500
Milhouse 30.

