WEBVTT

00:01.630 --> 00:03.219
Hello, this is Dr. Miller, and this

00:03.220 --> 00:04.569
is Episode three point one of

00:04.570 --> 00:05.570
assembly

00:06.550 --> 00:07.659
today we're going to talk about

00:07.660 --> 00:10.330
changing data sizes, multiplication

00:10.450 --> 00:11.450
and division.

00:12.540 --> 00:13.619
Changing sizes.

00:14.790 --> 00:16.469
So changing sizes, we want to take

00:16.470 --> 00:17.939
something and we want to either make

00:17.940 --> 00:19.710
it smaller or make it bigger,

00:20.340 --> 00:21.859
so making it smaller means that

00:22.020 --> 00:23.459
we're going to just move it to a

00:23.460 --> 00:24.529
smaller register.

00:24.990 --> 00:27.030
And this can be converting from a

00:27.090 --> 00:29.309
word to a bite and removing

00:29.310 --> 00:30.409
the upper eight bits.

00:31.500 --> 00:33.117
So if you remember, X is composed

00:33.690 --> 00:35.013
of two smaller registers, H

00:35.880 --> 00:37.829
and A-L, and so

00:37.830 --> 00:38.830
inside of X, A-L

00:39.750 --> 00:40.828
would have three, four

00:41.880 --> 00:44.189
X and H would have

00:44.190 --> 00:45.270
one to hex.

00:45.940 --> 00:47.165
So if we move into s.L H,

00:48.630 --> 00:50.198
right, the number one two in Hex

00:50.700 --> 00:52.219
would get moved into s.L.

00:52.800 --> 00:54.659
So we're taking something X and

00:54.660 --> 00:56.399
we're moving it into a smaller one.

00:56.400 --> 00:58.109
So we just remove the the bits that

00:58.110 --> 00:59.110
we don't need.

01:04.379 --> 01:05.909
If we want to increase the size,

01:05.910 --> 01:07.019
then we have to care about things

01:07.020 --> 01:08.699
like the sign, so we've talked about

01:08.700 --> 01:10.709
to compliment and you should

01:10.710 --> 01:12.329
have the ability to write the number

01:12.330 --> 01:13.898
negative seven into a compliment

01:14.370 --> 01:15.510
using one bite.

01:16.470 --> 01:17.939
You can take the time to do that and

01:17.940 --> 01:19.139
we'll show the results on the next

01:19.140 --> 01:20.140
slide.

01:21.980 --> 01:23.810
So negative seven is

01:24.080 --> 01:25.670
zero x F nine,

01:26.690 --> 01:28.454
and so we can move into the register

01:28.580 --> 01:30.639
ball, the number negative seven.

01:31.070 --> 01:32.749
So again, we have that top bit being

01:32.750 --> 01:33.750
our sign.

01:33.830 --> 01:35.496
And then we have two ways in order

01:35.540 --> 01:37.489
to increase the size, we can

01:37.490 --> 01:39.319
either use sign extend so we

01:39.320 --> 01:40.519
know that we're using signed

01:40.520 --> 01:42.739
numbers. And so we want to extend

01:42.740 --> 01:44.014
the sign if needed or zero

01:44.930 --> 01:46.849
extend if we don't care about the

01:46.850 --> 01:48.418
sign and we just want to fill it

01:48.470 --> 01:49.470
with zeros.

01:50.690 --> 01:52.459
So, for example, we move into B L

01:52.460 --> 01:54.439
negative seven and then if we do

01:54.440 --> 01:56.359
move sign, extend into a bigger

01:56.360 --> 01:58.550
register X B.L.

01:59.000 --> 02:00.779
because this top bit is a one.

02:00.810 --> 02:02.540
Remember when we if we convert F

02:02.870 --> 02:04.519
is one one, one one.

02:05.360 --> 02:07.519
So it'll fill that all with ones.

02:07.520 --> 02:09.110
And so X will have

02:09.530 --> 02:11.599
f f f f f

02:11.750 --> 02:12.750
f nine.

02:14.170 --> 02:15.836
If we do the same thing into, say,

02:16.240 --> 02:18.159
X, right, the no

02:19.300 --> 02:21.370
negative seven and we use

02:21.400 --> 02:23.229
Psionics, then again it will fill it

02:23.230 --> 02:25.419
with zeros but it'll be an X

02:25.420 --> 02:26.547
as opposed to X, right.

02:27.250 --> 02:28.629
X is thirty two bits.

02:29.050 --> 02:30.729
X is 16 bits.

02:33.250 --> 02:35.229
And if the number is not

02:35.230 --> 02:36.896
signed, so for example, the number

02:37.000 --> 02:38.860
seven, so zero seven,

02:39.370 --> 02:41.139
then we're going to fill the bits

02:41.140 --> 02:42.129
with zeros.

02:42.130 --> 02:44.080
And so if I move with a sign, extend

02:44.220 --> 02:45.250
XBRL,

02:46.060 --> 02:47.677
the number seven doesn't have the

02:47.740 --> 02:49.599
top it set and we're

02:49.600 --> 02:51.039
saying fill it with zeros if it's a

02:51.040 --> 02:52.810
zero. And so that's what will happen

02:55.300 --> 02:56.819
then. We also have zero extend.

02:56.830 --> 02:58.509
So basically we say we don't care if

02:58.510 --> 02:59.769
the number is negative or not.

02:59.770 --> 03:01.099
We want to put zeros in it.

03:01.690 --> 03:03.356
So if I do the same operation move

03:03.460 --> 03:05.319
be all negative seven again, it's F

03:05.320 --> 03:06.129
nine.

03:06.130 --> 03:07.453
If I move zero, extend into

03:08.050 --> 03:09.639
X from B.L.,

03:10.000 --> 03:11.000
it'll be

03:11.830 --> 03:13.509
six zeros and then F nine.

03:13.630 --> 03:14.904
So the top zeros, top bits

03:15.520 --> 03:16.569
are filled with zero.

03:18.110 --> 03:19.678
Again, I can move into this is a

03:19.880 --> 03:21.889
thirty two to register eight, but

03:22.400 --> 03:24.460
this is a 16 bit register

03:24.470 --> 03:26.419
again eight bits and so this

03:26.420 --> 03:28.189
is how I can change any of my signs.

03:28.740 --> 03:30.259
And then we get the same result

03:30.560 --> 03:32.449
on this one zero extender sign exten

03:32.450 --> 03:35.000
because this number is positive.

03:35.270 --> 03:36.649
So it doesn't have that top it set.

03:36.650 --> 03:37.519
So it would have filled it with

03:37.520 --> 03:39.110
zeros anyway, but zero and

03:39.440 --> 03:40.879
guarantees that it will fill it with

03:40.880 --> 03:41.880
zeros.

03:45.710 --> 03:47.269
So arithmetic, again, we've talked

03:47.270 --> 03:49.099
about to compliment, so this allows

03:49.100 --> 03:50.990
for both signed and unsigned numbers

03:51.950 --> 03:53.665
and then we've mentioned briefly we

03:53.960 --> 03:55.759
have these flags and these flags

03:55.760 --> 03:57.949
will get set when you do some

03:58.250 --> 03:59.209
operations.

03:59.210 --> 04:01.119
And so, for example, the carry flag.

04:01.760 --> 04:03.139
So if I have to

04:04.130 --> 04:06.460
16 bit numbers, zeros.

04:06.710 --> 04:08.749
So here's my 16 pin number zero

04:08.750 --> 04:09.926
zero to see and my other

04:10.610 --> 04:12.830
16 bit number F F F F.

04:13.370 --> 04:14.840
Right. If these are not signed

04:14.870 --> 04:16.069
numbers, i.e.

04:16.070 --> 04:17.208
they're not stored in twos

04:17.209 --> 04:18.483
compliment, then when I go

04:19.130 --> 04:20.539
ahead and add them together,

04:20.959 --> 04:22.690
right. Then I get a what we call

04:22.700 --> 04:24.139
carry or overflow.

04:24.230 --> 04:26.089
And so if these were going

04:26.090 --> 04:27.829
into a 16 bit register then our

04:27.830 --> 04:29.689
carry flag gets get set to say

04:30.140 --> 04:31.669
the number we're trying to store is

04:31.670 --> 04:33.589
too big to store in a sixteen

04:33.590 --> 04:34.590
bit register.

04:35.120 --> 04:36.579
But if I were using a 32 bit

04:36.590 --> 04:38.119
register, then I'm just taking two

04:38.120 --> 04:39.786
numbers. And clearly this is not a

04:39.920 --> 04:41.899
negative number because all

04:41.900 --> 04:43.249
the rest of the top bits are not

04:43.250 --> 04:44.250
set.

04:44.420 --> 04:45.529
And so these two numbers are

04:45.530 --> 04:47.196
positive. And so this is my result

04:47.600 --> 04:49.579
of doing adding to positive

04:49.580 --> 04:51.470
numbers together in a thirty two but

04:51.500 --> 04:52.500
register and again,

04:53.600 --> 04:55.266
flags will get set to carry a flag

04:55.700 --> 04:57.199
is just one example.

05:01.180 --> 05:02.180
Multiplication.

05:03.700 --> 05:05.319
So we're multiplication, we have two

05:05.320 --> 05:06.888
different op codes, so the first

05:07.240 --> 05:08.799
one is going to be mall and this is

05:08.800 --> 05:09.870
for unsigned numbers.

05:09.880 --> 05:11.769
So numbers that are always positive

05:12.730 --> 05:15.089
and we can use a eight bit register.

05:15.250 --> 05:16.250
So Al is implicit

05:17.410 --> 05:18.537
in here. And so we take

05:19.360 --> 05:20.585
the source times al store

05:21.250 --> 05:22.509
the result in X..

05:22.510 --> 05:24.100
So if I do mobile

05:24.400 --> 05:25.959
that's going to multiply B.L.

05:26.110 --> 05:28.089
Times Al and store the result

05:28.090 --> 05:29.139
in X.

05:30.130 --> 05:31.839
If I have a sixteen bit register

05:32.470 --> 05:34.029
then we're going to implicitly

05:34.030 --> 05:36.129
multiply by X that register

05:36.130 --> 05:37.480
times the source that I pick.

05:37.500 --> 05:39.130
So in this example, SCIEX,

05:39.820 --> 05:41.388
so in this example I'll take six

05:41.860 --> 05:43.281
times a X and then I'll store

05:43.930 --> 05:46.029
the top 16 bits

05:46.030 --> 05:47.030
in D, D, X and

05:48.100 --> 05:50.079
the bottom sixteen bits and X.

05:51.540 --> 05:52.720
And then if we have a thirty two bit

05:52.740 --> 05:54.870
register, we are again

05:54.900 --> 05:56.190
mall SBX,

05:56.760 --> 05:58.649
well, times a source, so

05:58.650 --> 05:59.650
X times SBX and

06:00.630 --> 06:02.100
then the top thirty two bits get

06:02.110 --> 06:03.720
stored in E, D, X

06:04.080 --> 06:05.759
and the bottom thirty two bits get

06:05.770 --> 06:07.259
stored in E, X.

06:09.260 --> 06:11.019
So here are a couple of examples,

06:11.030 --> 06:13.130
so, for example, we do more B.L.,

06:13.550 --> 06:15.619
so Ebix has to

06:15.650 --> 06:17.329
which implicit means B.L.

06:17.330 --> 06:18.229
has the number two.

06:18.230 --> 06:19.230
So two times 10 is

06:20.180 --> 06:21.180
20.

06:21.440 --> 06:23.155
We multiply those together and then

06:23.240 --> 06:24.906
we can see that are a result is 14

06:25.100 --> 06:27.019
and Hecks, which is the

06:27.020 --> 06:28.730
same as 20 in decimal.

06:29.690 --> 06:30.499
And the second one, we're

06:30.500 --> 06:31.990
multiplying by six.

06:32.690 --> 06:34.399
And so I take X

06:34.520 --> 06:36.380
or X, write the number 10,

06:37.850 --> 06:40.129
multiplying that by six

06:40.130 --> 06:41.950
three. So I should get 30.

06:42.410 --> 06:43.635
And if you do that, it is

06:44.330 --> 06:46.149
in here one

06:46.160 --> 06:47.570
E is our result

06:48.080 --> 06:49.249
again. Notice that.

06:49.550 --> 06:51.118
So in the first example, we only

06:51.290 --> 06:53.060
modified X.

06:54.160 --> 06:56.049
Or to be more precise acts,

06:56.560 --> 06:57.879
and the second, remember, we're

06:57.880 --> 07:00.519
doing a 16 bit multiplication

07:00.790 --> 07:02.064
and so notice here how the

07:02.860 --> 07:04.550
beef disappeared, right?

07:04.570 --> 07:06.850
So we took the

07:07.180 --> 07:09.129
beef in here and we set it to zero

07:09.130 --> 07:10.509
because the top bits of that were

07:10.510 --> 07:11.289
set.

07:11.290 --> 07:13.359
So if I take three times 10,

07:13.930 --> 07:15.029
that gives me 30.

07:15.430 --> 07:17.529
And so 30 goes in the bottom part

07:17.530 --> 07:19.098
and then zeros get filled in the

07:19.300 --> 07:20.300
top.

07:21.050 --> 07:22.459
And then if I do a full thirty two

07:22.460 --> 07:24.319
bit multiplication, so I take

07:24.680 --> 07:26.639
Yak's, which is gadzooks

07:26.660 --> 07:27.689
A and I multiply that

07:28.490 --> 07:30.559
by Ebix, so 10 times two

07:30.560 --> 07:31.519
is 20.

07:31.520 --> 07:32.520
Again, we got 14,

07:33.410 --> 07:35.269
which is 20 and Hecks, but then we

07:35.270 --> 07:37.040
erased all of the

07:37.190 --> 07:38.149
IDEX.

07:38.150 --> 07:39.949
So feed beef disappeared.

07:44.090 --> 07:45.799
So this is an example you can try on

07:45.800 --> 07:48.019
your own so you can either

07:48.020 --> 07:49.970
try and do it longhand

07:50.360 --> 07:52.699
or you can open up a terminal

07:52.700 --> 07:54.589
and enter your program and

07:54.590 --> 07:56.540
then print off the result and see

07:56.750 --> 07:57.829
what would change.

08:01.090 --> 08:02.350
Now, if we want to do sign more,

08:03.040 --> 08:04.363
sign multiplication, we use

08:05.020 --> 08:06.819
the OP code I.M.,

08:07.010 --> 08:09.069
so that's going to take either

08:09.070 --> 08:10.540
to thirty two bit numbers or a

08:10.660 --> 08:12.219
thirty two bit number and a memory

08:12.220 --> 08:13.570
address or a thirty two

08:14.080 --> 08:15.519
to thirty two bit numbers

08:16.390 --> 08:18.279
and a immediate and it's

08:18.280 --> 08:19.660
going to multiply them together.

08:20.770 --> 08:22.660
So for example, if I do I'm all

08:23.200 --> 08:25.200
SBX then X

08:25.210 --> 08:27.429
gets the result of multiplying X

08:27.430 --> 08:28.809
times X

08:29.890 --> 08:31.840
or if I do I'm all IACI.

08:31.850 --> 08:33.279
Eddi twenty five.

08:33.280 --> 08:34.799
That's going to take Eddi times

08:35.049 --> 08:36.519
twenty five and then store the

08:36.580 --> 08:38.049
result in Essi.

08:41.200 --> 08:43.029
So here is an example, so if I

08:43.030 --> 08:45.100
do, I'm all SBX,

08:45.760 --> 08:47.230
it's going to take X, multiply

08:47.740 --> 08:49.629
it by X and then store

08:49.630 --> 08:51.039
the result in X.

08:51.880 --> 08:53.769
So again, we have a negative number.

08:53.770 --> 08:55.044
So negative, two times ten

08:55.630 --> 08:57.051
is negative 20 and you should

08:57.490 --> 08:59.739
be able to using to complement,

08:59.740 --> 09:01.299
convert that and verify that it is

09:01.300 --> 09:02.469
the number negative 20.

09:04.810 --> 09:05.810
Division,

09:07.180 --> 09:09.179
so division is like multiplication,

09:09.190 --> 09:11.169
we have, again, unsigned with

09:11.170 --> 09:13.149
div or we have signed with

09:13.150 --> 09:14.150
it.

09:14.350 --> 09:15.699
And then the result, so we have a

09:15.700 --> 09:16.880
cushion and the remainder.

09:16.930 --> 09:18.279
So when you do division, right, how

09:18.280 --> 09:19.839
many times it goes into that number

09:19.840 --> 09:21.310
is your quotient and then your

09:21.370 --> 09:22.900
remainder is what's left.

09:24.040 --> 09:26.350
And so again, we have different

09:27.130 --> 09:29.049
registers to get used depending

09:29.050 --> 09:30.489
on if we're doing an eight bit or a

09:30.490 --> 09:32.200
sixteen bit or a thirty two bit.

09:33.130 --> 09:35.049
So again, we are going to take, for

09:35.050 --> 09:36.879
example, X and divide it

09:36.880 --> 09:37.880
by the source store.

09:38.200 --> 09:40.029
The question in a L store the

09:40.030 --> 09:41.030
remainder and H if

09:41.950 --> 09:43.569
we're doing sixteen bit again, it's

09:43.570 --> 09:45.187
going to use the entire registers

09:45.490 --> 09:46.490
of X and X put

09:47.350 --> 09:48.918
together and divide those by the

09:49.000 --> 09:50.666
source and then store the quotient

09:51.070 --> 09:53.350
and X and the remainder index.

09:54.790 --> 09:56.230
And then if we have a thirty two bit

09:56.500 --> 09:57.529
we are using IDEX and

09:58.360 --> 09:59.732
X together and then dividing

10:00.190 --> 10:02.049
those by the source and then the

10:02.050 --> 10:03.909
question gets stored in X and

10:03.910 --> 10:05.799
the remainder gets stored in X.

10:08.780 --> 10:10.450
So in this, I put an example,

10:10.820 --> 10:11.947
so here we have has one

10:12.830 --> 10:14.149
hundred in decimal

10:15.320 --> 10:16.879
and then Ebix has seven

10:17.300 --> 10:19.249
and I just do a division

10:19.250 --> 10:20.250
of Ebix.

10:20.330 --> 10:21.679
So again, that's going to take

10:22.550 --> 10:23.550
X and X together as

10:24.470 --> 10:26.450
my number and then divide it by

10:27.140 --> 10:28.140
SBX.

10:28.310 --> 10:29.750
And so my remainder,

10:30.260 --> 10:31.969
if we take one hundred divided by

10:31.970 --> 10:33.500
seven is E,

10:33.980 --> 10:36.049
you can convert that and

10:36.050 --> 10:38.119
then the remainder is two.

10:38.720 --> 10:40.340
So we get the number ninety eight

10:40.800 --> 10:42.679
when we multiply seven times

10:42.680 --> 10:44.509
E and then we have a remainder

10:44.510 --> 10:45.510
of two

10:46.490 --> 10:47.809
in here. I put you need to zero

10:48.680 --> 10:49.680
or else.

10:51.050 --> 10:52.759
So if you forget to zero it out

10:52.970 --> 10:54.679
and you run this code and you can

10:54.680 --> 10:56.297
type it in yourself, you will get

10:56.600 --> 10:58.700
a floating point exception because

10:59.030 --> 11:00.469
the result that I tried to store

11:00.470 --> 11:02.059
couldn't fit in

11:02.460 --> 11:03.630
X, right.

11:03.650 --> 11:04.970
So when you're doing the division,

11:05.270 --> 11:07.034
we couldn't store that full thing in

11:07.070 --> 11:08.687
X, and so we get a floating point

11:08.690 --> 11:09.690
exception.

11:09.920 --> 11:11.449
So this isn't a mistake that often

11:11.450 --> 11:12.469
my students make.

11:15.140 --> 11:16.789
So today, we talked about changing

11:16.790 --> 11:17.868
sizes, we talked about

11:18.620 --> 11:20.419
doing multiplication and doing

11:20.420 --> 11:21.420
division.

11:23.020 --> 11:24.159
In the future, we're going to learn

11:24.160 --> 11:25.434
about doing multiplication

11:26.440 --> 11:27.959
and division, given some actual

11:28.120 --> 11:29.649
examples of typing it in

11:29.980 --> 11:31.450
and then doing comparisons and

11:31.960 --> 11:32.960
doing looping,

11:34.390 --> 11:35.559
if you have questions, you can

11:35.560 --> 11:37.559
contact me at Ramjet, you and Kada

11:37.570 --> 11:39.236
Edu and you can find me on Twitter

11:39.610 --> 11:40.570
at Milhouse 30.

