Hello. This is Dr Miller, And this is Episode 14.5 of Assembly.
Today, we're going to do an example using Malik in assembly with structures.
So, Malik structure example.
So we're gonna 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 gonna do is we're gonna leverage Malik 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 resident one and then dot TV
also rez de one.
And then we have our end struck.
And then we're gonna have our format
for our print f
all about a new line, followed by zero,
and then in here, we're gonna have some X turns.
So, friend tough
and get time.
so the first thing that we're going to do is we're going to allocate some space on the stack. So do a move.
B p E s p.
So Yes, Pea.
Four. So a pointer is four bites were doing 32 bit assembly.
So now we're going to allocate space. So we're gonna push
eight hex. So we reserved two doubles.
we got to correct the stack. Addy sp four. So you push something on so here will correct the stack,
and then we're going to save our pointer here. So movie VP,
t minus four.
um, did our copy, and then we subtracted. So it's it down by four for local variable. And then the result of
Malik is an e X.
So now we're ready to call our get time, so push.
push zero. So we looked at the arguments last time Anyone call
clock underscore, get time.
And then we pushed on to arguments. So we'll do. Add e S p eight
Kate. So that should get our call. And now we're ready to
do our print. So here we have to do a little bit more worked emitted last time.
So move into db X.
We're going to use our pointer. So we got CBP minus four
is the pointer to that
and then move into yea X. So now we do
E b X, which is our pointer and then we're gonna add my time. Got TV,
underscore and sec. Right? So we put our parameters in reverse order
and then push x. So we pushed that value that we loaded.
Now we gotta do the next one. So push.
going to Eby X
plus and then do our next offset. So my time, don t the
And then we're gonna push that value onto the stack. So you pushed to things onto the stack. We need to push our formats, a movie, a x format,
push your ex,
and then we'll call print F.
And then after we do that, we have to correct the stack. We pushed on three arguments, so add yes, p
12 and then correct the stack for original ones. I'll just to him separate ad e s p four.
So we did a subtract at the top. And so now we need to do our ad.
Looks like I think we missed. Ah.
type that one wrong.
So we can do 14.5, and then we can also run.
I have the sea version.
here we go.
So now we can we can run both of them, and we can see that we get nearly the same results. I'm so clearly we implemented it properly
so we can see that basically, the big difference is that we had to save our pointer that we got from our Mellick.
And then when we wanted to get the data, we had toe load that pointer
into a memory location, and then calculator offsets one of these. Is it off zero? Their only ones that offset for
depending on how they're laid out.
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,
um, optimized in this way. Otherwise, sometimes if they're not optimizing,
they may show you, um, a little bit different code than that.
So today we did an example using Malik and assembly, and we used structures for that.
Looking forward, we're gonna look at some case statements and then jump tables created by case statements.
Do you have questions? You can email me, Miller, MJ at you and Kate out. You do you And you can find me on Twitter at Milhouse 30