WEBVTT

00:00.360 --> 00:01.949
Hello, this is Dr. Miller and this

00:01.950 --> 00:03.567
is Episode fourteen point five of

00:03.720 --> 00:04.720
Assembly.

00:07.160 --> 00:08.875
Today, we're going to do an example

00:09.140 --> 00:10.969
using Mallik in assembly

00:10.970 --> 00:11.970
with structures, so

00:12.980 --> 00:14.330
Mallik structure, for example.

00:15.420 --> 00:16.639
So we're going to do a similar one

00:16.640 --> 00:17.769
to what we did last time.

00:17.780 --> 00:18.979
So we're going to get the real time

00:18.980 --> 00:21.039
from the clock, underscore,

00:21.050 --> 00:22.519
get time, system call.

00:22.550 --> 00:23.599
And then what we're going to do is

00:23.600 --> 00:25.429
we're going to leverage mallock

00:25.760 --> 00:27.499
to access our structure like we did

00:27.500 --> 00:28.500
before.

00:30.790 --> 00:32.390
So I've already got this started.

00:32.759 --> 00:34.689
So last time we had

00:34.690 --> 00:36.099
one called my time,

00:37.300 --> 00:38.439
this is our structure.

00:43.330 --> 00:45.100
And this is a

00:45.160 --> 00:46.780
red one and then

00:47.050 --> 00:48.050
to the

00:49.870 --> 00:51.100
nanoseconds

00:54.190 --> 00:56.049
also as the one.

00:59.760 --> 01:01.889
And then we have our end struck.

01:03.270 --> 01:04.199
And then we're going to have our

01:04.200 --> 01:05.200
format

01:06.660 --> 01:07.709
for our print F.

01:18.860 --> 01:20.183
I'll buy a new one followed

01:20.750 --> 01:21.750
by zero.

01:23.560 --> 01:24.999
And then in here, we're going to

01:25.000 --> 01:26.159
have some externals,

01:28.270 --> 01:29.319
so print of.

01:31.860 --> 01:32.860
Malik.

01:41.730 --> 01:42.780
And get time.

01:45.060 --> 01:46.481
All right, so the first thing

01:46.980 --> 01:48.499
that we're going to do is we're

01:48.510 --> 01:50.225
going to allocate some space on the

01:50.340 --> 01:51.989
stack. So do we move

01:53.400 --> 01:55.140
SBP E.S.P,

01:56.970 --> 01:58.680
some E.S.P

01:59.730 --> 02:01.819
four. So pointer is four bytes.

02:01.830 --> 02:03.269
We're doing thirty two bit assembly.

02:05.370 --> 02:07.019
So now we're going to allocate

02:07.020 --> 02:08.020
space.

02:08.250 --> 02:10.469
So we're going to push eight

02:10.470 --> 02:11.259
Hecks.

02:11.260 --> 02:12.629
So we reserve to

02:13.110 --> 02:14.110
double's.

02:19.370 --> 02:20.709
And we've got to correct this attack

02:20.710 --> 02:22.270
ad ESP four,

02:22.690 --> 02:24.356
so push something on, so here will

02:24.460 --> 02:26.199
correct the stack and then we're

02:26.200 --> 02:28.060
going to save our pointer here.

02:28.150 --> 02:29.810
So move SBP

02:30.930 --> 02:32.559
Ops, the B,

02:33.790 --> 02:35.559
E minus four,

02:36.100 --> 02:37.100
because we

02:38.020 --> 02:39.830
did our copy and then we subtracted.

02:39.850 --> 02:41.589
So it's A down by four for our local

02:41.590 --> 02:43.539
variable and then the result of

02:44.040 --> 02:45.580
Amalek is an X.

02:46.930 --> 02:48.219
So now we're ready to call our get

02:48.220 --> 02:49.449
time. So push

02:50.350 --> 02:51.350
X,

02:52.900 --> 02:54.530
push zero.

02:54.640 --> 02:56.199
So we looked at the arguments last

02:56.200 --> 02:58.239
time and then we call

02:59.890 --> 03:02.080
Clark underscore and get

03:02.230 --> 03:03.230
time

03:04.180 --> 03:06.210
and then we push on two arguments.

03:06.220 --> 03:08.560
So we'll do add E.S.P

03:08.860 --> 03:09.860
eight.

03:11.110 --> 03:12.874
OK, so that you get our call and now

03:12.940 --> 03:13.940
we're ready to

03:14.800 --> 03:15.800
do our print.

03:15.850 --> 03:17.516
So here we have to do a little bit

03:17.590 --> 03:19.256
more work than we did last time to

03:19.630 --> 03:21.460
move into SBX.

03:23.450 --> 03:24.829
And we're going to use our our

03:24.830 --> 03:26.660
pointer, so we got SBP

03:26.780 --> 03:28.639
minus four is

03:28.640 --> 03:29.640
the pointer to that

03:30.740 --> 03:33.099
and then move into yak's.

03:33.500 --> 03:35.449
So now we do Ebix,

03:35.450 --> 03:36.675
which is our pointer, and

03:37.430 --> 03:39.949
then we're going to add my time

03:40.430 --> 03:41.480
dot TV.

03:42.400 --> 03:44.460
Underscore and SEC,

03:44.470 --> 03:46.719
right? So we put our parameters

03:46.720 --> 03:47.720
in reverse order

03:48.610 --> 03:49.610
and then push yak's,

03:51.070 --> 03:52.359
so we push that value that we

03:52.360 --> 03:53.360
loaded.

03:55.000 --> 03:56.319
Now we've got to do the next one.

03:56.320 --> 03:57.519
So push.

03:58.360 --> 04:00.930
Sorry, move x,

04:01.960 --> 04:03.399
I'm going to EB X

04:04.570 --> 04:06.360
plus and then do our next offset.

04:06.370 --> 04:07.370
So my time that

04:08.420 --> 04:10.120
t the

04:11.320 --> 04:12.430
underscore a sec.

04:15.020 --> 04:16.069
And then we're going to push that

04:16.070 --> 04:17.687
value onto the stack, so you push

04:17.720 --> 04:19.159
two things onto the stack, we need

04:19.160 --> 04:20.088
to push our format.

04:20.089 --> 04:22.010
So move your format,

04:23.540 --> 04:24.949
push X,

04:25.460 --> 04:27.500
and then we'll call printf.

04:28.700 --> 04:29.959
And then after we do that, we have

04:29.960 --> 04:30.739
to correct the stack.

04:30.740 --> 04:32.110
We pushed on three arguments.

04:32.120 --> 04:33.829
So add E.S.P.

04:35.970 --> 04:37.048
Twelve, and then crack

04:38.070 --> 04:39.599
the stack for original ones, I'll

04:39.600 --> 04:40.776
just do them separate ad

04:41.490 --> 04:43.439
E.S.P four.

04:44.490 --> 04:46.254
So we did subtract at the top and so

04:46.380 --> 04:47.519
now we need to do our ad.

04:52.940 --> 04:53.940
Oh, looks

04:54.800 --> 04:56.740
like I think we messed up

04:57.620 --> 04:58.620
I.

05:01.740 --> 05:02.869
Type that one wrong.

05:05.760 --> 05:06.760
All right,

05:08.520 --> 05:10.409
so we can do fourteen

05:10.410 --> 05:12.389
point five and then we can also

05:12.390 --> 05:13.390
run, I have

05:14.250 --> 05:15.569
the C version.

05:18.870 --> 05:19.870
OK.

05:27.400 --> 05:28.400
Here we go.

05:29.020 --> 05:30.441
So now we can we can run both

05:30.910 --> 05:32.499
of them and we can see that we get

05:32.620 --> 05:34.149
nearly the same results.

05:34.810 --> 05:36.429
So clearly we implemented it

05:36.730 --> 05:37.730
properly.

05:41.160 --> 05:42.875
So we can see the basically the big

05:43.140 --> 05:44.639
difference is that we had to save

05:44.640 --> 05:46.208
our pointer that we got from our

05:46.380 --> 05:47.556
mellark and then when we

05:48.360 --> 05:50.399
wanted to get the data, we had to

05:50.670 --> 05:52.560
load that pointer

05:53.070 --> 05:54.779
into a memory location

05:55.050 --> 05:56.373
and then calculator offset.

05:56.970 --> 05:58.439
So one of these is it offset zero

05:58.440 --> 05:59.669
there. They're the ones that offset

05:59.670 --> 06:01.589
for depending on

06:01.590 --> 06:02.590
how they're laid out.

06:03.570 --> 06:04.570
And then we just had

06:05.430 --> 06:06.753
to make sure that we passed

06:07.350 --> 06:08.229
it the right pointer.

06:08.230 --> 06:09.569
So here we happen to have the

06:09.570 --> 06:11.009
pointer in a compiler might

06:12.060 --> 06:13.430
optimize in this way.

06:13.860 --> 06:15.269
Otherwise, sometimes if they're not

06:15.270 --> 06:17.129
optimizing, they may show

06:17.130 --> 06:18.404
you a little bit different

06:19.230 --> 06:20.230
code than that.

06:23.030 --> 06:24.739
So today, we did an example using

06:24.740 --> 06:26.210
Mallik in assembly and we used

06:26.870 --> 06:27.980
structures for that.

06:29.420 --> 06:30.739
Looking forward, we're going to look

06:30.740 --> 06:32.504
at some key statements and then jump

06:32.600 --> 06:34.190
tables created by case statements.

06:35.220 --> 06:36.199
Do you have questions? You can

06:36.200 --> 06:37.572
e-mail me, MJ, at you in Edu

06:38.420 --> 06:40.009
and you can find me on Twitter at my

06:40.010 --> 06:40.579
house 30.

