WEBVTT

00:01.740 --> 00:03.449
Hello, this is Dr. Miller, and this

00:03.450 --> 00:04.773
is Episode six point one of

00:04.920 --> 00:05.920
Assembly.

00:09.890 --> 00:10.999
Today, we're going to talk about

00:11.000 --> 00:13.220
indirect addressing and variables.

00:14.960 --> 00:16.129
Indirect addressing,

00:17.270 --> 00:18.789
so indirect addressing is a way

00:19.100 --> 00:21.230
that we can point to some memory

00:21.590 --> 00:23.780
and we will do this

00:24.140 --> 00:25.414
by using things like we've

00:26.120 --> 00:27.120
already done before.

00:27.200 --> 00:29.149
So, for example, hello,

00:29.150 --> 00:31.249
Deb, this is a string, comma

00:31.250 --> 00:32.250
zero.

00:32.390 --> 00:34.007
So that is allocating some memory

00:34.700 --> 00:36.259
in RAM that

00:36.560 --> 00:37.638
we can then use inside

00:38.390 --> 00:39.390
of assembly.

00:39.710 --> 00:41.059
And again, we've been using it in

00:41.060 --> 00:43.009
class. So, for example, moving

00:43.010 --> 00:44.509
that value into yak's

00:45.020 --> 00:46.490
and then calling the print string.

00:47.270 --> 00:48.838
And so this is how we can define

00:49.490 --> 00:51.049
different pieces of data that we can

00:51.050 --> 00:52.609
use and we can also create

00:52.700 --> 00:53.700
variables.

00:54.260 --> 00:55.260
So variables.

00:56.660 --> 00:58.430
So variables are defined in one of

00:58.460 --> 01:00.039
the two sections, we have the

01:00.050 --> 01:01.422
abscess and we have the data

01:02.090 --> 01:03.511
section, so each one of these

01:04.040 --> 01:05.870
can have variables within it.

01:06.860 --> 01:07.999
And so we kind of define them

01:08.000 --> 01:09.799
differently. So in the data section,

01:10.310 --> 01:11.809
we use the name of the variable and

01:11.810 --> 01:12.986
then we say DB to define

01:13.730 --> 01:14.906
a bite and then zero, we

01:15.560 --> 01:16.560
give it a value.

01:16.910 --> 01:18.499
So within the data section, we can

01:18.500 --> 01:20.540
actually give things values,

01:21.170 --> 01:23.209
but in the best, we don't actually

01:23.390 --> 01:24.390
assign it a value so

01:25.310 --> 01:27.169
we can allocate space in

01:27.170 --> 01:28.609
the bÃÆsescu. We don't give it an

01:28.610 --> 01:29.479
initial value.

01:29.480 --> 01:30.799
And so that's the only difference.

01:30.800 --> 01:32.269
Why you would want to choose

01:32.720 --> 01:34.092
the data section or the best

01:34.640 --> 01:35.930
section is if

01:36.630 --> 01:38.419
if you want it to have a known

01:38.420 --> 01:40.129
value. So, for example, if you

01:40.130 --> 01:41.329
wanted to create a buffer where you

01:41.330 --> 01:43.094
were going to load in some data, you

01:43.250 --> 01:44.499
might use the best.

01:44.570 --> 01:46.069
But if you had a variable that was a

01:46.070 --> 01:47.599
counter or something, you might want

01:47.600 --> 01:48.600
to use the data.

01:51.630 --> 01:53.198
So here we can see some examples

01:53.460 --> 01:55.469
of of using these and

01:55.470 --> 01:56.819
so in this first one, when we move

01:56.820 --> 01:58.437
into a register, the value of our

01:58.770 --> 02:01.049
one, that's actually copying

02:01.050 --> 02:02.879
its address into

02:02.880 --> 02:04.519
X and then we're printing that.

02:04.980 --> 02:06.119
So we're printing the address.

02:06.120 --> 02:07.786
So the addresses one three four or

02:07.950 --> 02:09.960
five two zero eight seven two.

02:10.030 --> 02:11.490
Right. It's just some random value.

02:12.060 --> 02:13.439
And that's because the OS will give

02:13.440 --> 02:15.449
you different values within

02:15.450 --> 02:16.450
the system.

02:16.890 --> 02:18.030
And so here we are.

02:18.420 --> 02:19.739
We're printing that integer and then

02:19.740 --> 02:20.740
printing a new line.

02:21.090 --> 02:22.740
But when we say, get me the data at

02:23.100 --> 02:25.319
at the address, a variable

02:25.320 --> 02:26.398
one. So it dereference

02:27.330 --> 02:28.751
is that it'll copy that data.

02:29.220 --> 02:30.347
And so that's the value

02:31.110 --> 02:32.580
that we gave it,

02:33.110 --> 02:34.110
the number zero.

02:34.740 --> 02:35.909
And then we go ahead and print that

02:35.910 --> 02:37.229
in print and online and we can see

02:37.230 --> 02:38.939
that the number of zero is printed.

02:39.750 --> 02:41.219
So one of the big things is knowing,

02:41.220 --> 02:42.788
do you get the address or do you

02:43.110 --> 02:44.110
get the value at the

02:44.970 --> 02:46.709
address? And so that's the different

02:46.710 --> 02:47.788
notation here of using

02:48.720 --> 02:49.720
the brackets.

02:52.850 --> 02:54.418
And so we can do it both ways so

02:54.770 --> 02:56.809
we can move the

02:56.810 --> 02:58.639
value into yak's

02:58.640 --> 03:00.610
and we can do it for right.

03:00.670 --> 03:02.029
This will give us the address,

03:02.690 --> 03:04.849
whereas something like this,

03:04.850 --> 03:05.980
it'll move the bite.

03:05.990 --> 03:07.607
And so the very first bite is the

03:07.910 --> 03:08.910
letter H.

03:09.650 --> 03:11.360
And so we'll move that into A-L.

03:12.050 --> 03:13.618
But there is this notion that we

03:13.880 --> 03:15.379
have something called Lydie Little

03:15.380 --> 03:16.789
Indian, which we'll talk about

03:16.790 --> 03:17.659
later.

03:17.660 --> 03:18.979
But the bites are sort of in the

03:18.980 --> 03:20.646
reverse order that you might think

03:21.020 --> 03:21.889
of them.

03:21.890 --> 03:23.507
And so here we're actually moving

03:24.050 --> 03:26.150
the letters E and H into

03:26.170 --> 03:28.069
X because Acts is a 16

03:28.070 --> 03:29.070
bit register.

03:29.240 --> 03:31.399
A L is an eight bit register, X

03:31.400 --> 03:32.869
is a 32 bit register.

03:33.590 --> 03:35.599
And so here we can either copy

03:36.260 --> 03:37.534
eight bits or sixteen bits

03:38.180 --> 03:40.069
or thirty two bits of value

03:40.070 --> 03:41.059
from there.

03:41.060 --> 03:42.726
Now normally we wouldn't be moving

03:42.740 --> 03:44.509
string's into a register, but

03:44.930 --> 03:46.489
but we can get all of the different

03:46.490 --> 03:48.259
pieces of data and then we can

03:48.590 --> 03:50.179
do things like take our variable and

03:50.180 --> 03:52.069
we can add to

03:52.070 --> 03:53.589
it if we want to go a different

03:54.020 --> 03:55.020
location.

03:56.370 --> 03:58.085
So here's an example that you might

03:58.110 --> 03:59.669
do in a high level language, you

03:59.670 --> 04:01.050
might say something like

04:02.190 --> 04:04.189
Fred plus plus most

04:04.200 --> 04:05.489
of what we have to do is we have to

04:05.490 --> 04:07.349
load the value in from Fred

04:07.350 --> 04:09.016
into a register and then we can do

04:09.120 --> 04:10.159
some operation on it.

04:10.170 --> 04:11.542
So we add one to it and then

04:12.000 --> 04:13.617
we can save that data back to the

04:13.860 --> 04:14.860
register.

04:15.120 --> 04:16.799
Right. So this is copying the number

04:16.800 --> 04:18.750
18 back into Fred.

04:19.800 --> 04:21.809
And so that's how we can we can load

04:21.810 --> 04:24.029
some data to and from memory.

04:24.210 --> 04:25.859
And so these are type of operations

04:25.860 --> 04:27.629
that you would want to use when

04:27.630 --> 04:29.220
you're writing a program.

04:31.160 --> 04:33.019
So here's another example, and this

04:33.020 --> 04:35.100
is based off of the different

04:35.120 --> 04:35.959
fact that we have different

04:35.960 --> 04:38.119
addresses, so we have

04:38.120 --> 04:40.189
a string that has car Rockit horse,

04:41.420 --> 04:42.859
and so we can just print that in a

04:42.860 --> 04:43.860
normal fashion.

04:44.340 --> 04:46.100
Right. So we move it into called

04:47.180 --> 04:48.859
line online. That'll print the whole

04:48.860 --> 04:49.860
string.

04:49.940 --> 04:51.500
So we get car Rockit horse.

04:53.650 --> 04:55.479
So if we move the address into

04:55.480 --> 04:56.950
Yak's and then we add two four

04:57.310 --> 04:59.619
to it, we would skip the letters C,

04:59.650 --> 05:01.329
A, R and the space.

05:01.330 --> 05:02.439
And so that would point to the

05:02.440 --> 05:04.139
letter R, right.

05:04.150 --> 05:05.589
So we can have these addresses and

05:05.590 --> 05:06.779
we can manipulate them.

05:06.850 --> 05:08.467
So if we add four to that initial

05:08.470 --> 05:10.389
address of string, we will

05:10.390 --> 05:11.390
get the word

05:12.430 --> 05:13.430
rocket horse.

05:13.690 --> 05:14.690
Right.

05:15.260 --> 05:16.429
And then if you take it a step

05:16.430 --> 05:18.109
further and again, move the address

05:18.110 --> 05:20.439
of string into X and then at 11,

05:20.870 --> 05:22.730
so if you count out there's 11

05:22.970 --> 05:24.889
characters between the C

05:24.890 --> 05:25.890
and the H.

05:26.150 --> 05:27.469
And so now it just points to the

05:27.470 --> 05:28.670
word horse.

05:30.280 --> 05:32.550
So we add 11 to that address,

05:32.560 --> 05:33.829
right? We're adding to the address,

05:33.830 --> 05:35.229
not the actual value, and then we

05:35.230 --> 05:36.945
can call print string and print new

05:36.970 --> 05:37.909
line.

05:37.910 --> 05:39.069
And so we can see here that I

05:39.070 --> 05:41.110
printed off course as the last one.

05:41.980 --> 05:43.449
And so we have the ability to

05:43.450 --> 05:45.009
manipulate these addresses

05:45.550 --> 05:46.539
if we need to.

05:46.540 --> 05:48.789
And so a lot of times students

05:48.790 --> 05:50.456
or programs will allocate one big,

05:50.770 --> 05:52.749
long string and then

05:52.750 --> 05:54.159
they'll just calculate what the

05:54.160 --> 05:56.019
offset is that they need to go to

05:56.020 --> 05:57.735
in order to print a particular part

05:57.940 --> 05:58.570
of the string.

