Hello, this is Dr. Miller and this
is Episode fourteen point five of
Assembly.
Today, we're going to do an example
using Mallik in assembly
with structures, so
Mallik structure, for example.
So we're going to do a similar one
to what we did last time.
So we're going to get the real time
from the clock, underscore,
get time, system call.
And then what we're going to do is
we're going to leverage mallock
to access our structure like we did
before.
So I've already got this started.
So last time we had
one called my time,
this is our structure.
And this is a
red one and then
to the
nanoseconds
also as the one.
And then we have our end struck.
And then we're going to have our
format
for our print F.
I'll buy a new one followed
by zero.
And then in here, we're going to
have some externals,
so print of.
Malik.
And get time.
All right, so the first thing
that we're going to do is we're
going to allocate some space on the
stack. So do we move
SBP E.S.P,
some E.S.P
four. So pointer is four bytes.
We're doing thirty two bit assembly.
So now we're going to allocate
space.
So we're going to push eight
Hecks.
So we reserve to
double's.
And we've got to correct this attack
ad ESP four,
so push something on, so here will
correct the stack and then we're
going to save our pointer here.
So move SBP
Ops, the B,
E minus four,
because we
did our copy and then we subtracted.
So it's A down by four for our local
variable and then the result of
Amalek is an X.
So now we're ready to call our get
time. So push
X,
push zero.
So we looked at the arguments last
time and then we call
Clark underscore and get
time
and then we push on two arguments.
So we'll do add E.S.P
eight.
OK, so that you get our call and now
we're ready to
do our print.
So here we have to do a little bit
more work than we did last time to
move into SBX.
And we're going to use our our
pointer, so we got SBP
minus four is
the pointer to that
and then move into yak's.
So now we do Ebix,
which is our pointer, and
then we're going to add my time
dot TV.
Underscore and SEC,
right? So we put our parameters
in reverse order
and then push yak's,
so we push that value that we
loaded.
Now we've got to do the next one.
So push.
Sorry, move x,
I'm going to EB X
plus and then do our next offset.
So my time that
t the
underscore a sec.
And then we're going to push that
value onto the stack, so you push
two things onto the stack, we need
to push our format.
So move your format,
push X,
and then we'll call printf.
And then after we do that, we have
to correct the stack.
We pushed on three arguments.
So add E.S.P.
Twelve, and then crack
the stack for original ones, I'll
just do them separate ad
E.S.P four.
So we did subtract at the top and so
now we need to do our ad.
Oh, looks
like I think we messed up
I.
Type that one wrong.
All right,
so we can do fourteen
point five and then we can also
run, I have
the C version.
OK.
Here we go.
So now we can we can run both
of them and we can see that we get
nearly the same results.
So clearly we implemented it
properly.
So we can see the basically the big
difference is that we had to save
our pointer that we got from our
mellark and then when we
wanted to get the data, we had to
load that pointer
into a memory location
and then calculator offset.
So one of these is it offset zero
there. They're the ones that offset
for depending on
how they're laid out.
And then we just had
to make sure that we passed
it the right pointer.
So here we happen to have the
pointer in a compiler might
optimize in this way.
Otherwise, sometimes if they're not
optimizing, they may show
you a little bit different
code than that.
So today, we did an example using
Mallik in assembly and we used
structures for that.
Looking forward, we're going to look
at some key statements and then jump
tables created by case statements.
Do you have questions? You can
e-mail me, MJ, at you in Edu
and you can find me on Twitter at my
house 30.