Hello, this is Dr. Miller, and this
is Episode fourteen point three of
Assembly today
we're going to talk about using
structures.
So we'll give a structure example,
so here's an example where we have a
structure that is defined inside of
C. We can see the struct times
back and it's called start
and we'll go ahead and see that
we're going to call Klok,
underscore, get time.
And that's going to be used to fill
that structure with the
data about the number of seconds and
the number of nanoseconds.
And then we go ahead and print it
off inside of this C
program.
So here, if we take that code and we
paste it into a D compiler
or the compiler explorer,
we're going to see that we get
offsets minus 12 and minus 16
as denoted by those arrows.
And so as we push them on
in reverse order, we know that the
number of seconds is going to be
the first field inside of our
structure.
And so we'll go ahead and define
that and we will
put the data on the stack
and then call our function.
So our example, we're going to write
a program that reads in that time
using the get clocked, underscore,
get time, and then we're going to
print it out just like we do in the
example.
All right, so I've already started
this.
So what we're going to want to do is
we're going to define our structure.
So here we use the key word struck
and I'll call this my time.
And then we're going to use the dot
notation to sort of separate the
parts. And we've got to underscore
and then we use seconds.
And when we look in the code, we see
that it uses a D word.
So we're going to say, rose the
one,
and then the next part is the
nanoseconds.
And for that, we'll also
if we look in the code, we see that
it has one D word.
And then we have to use the
key word here and struck
to tell us that that's the end of
our structure.
We're also going to be printing
something out, so we'll define our
format.
The time is
and we use LDA
for our format, specifying four
seconds
and the same thing for nanoseconds.
Here, we're going to be using a
couple of different functions, so
we'll just declare those as
externals.
So we got print
and get our clerk
so called clock on the score,
get time.
All right. And so I'll put in a few
things over where the bugging will
get to see it.
So, for example, we're going to
push.
Known values, we can see it on the
stack.
Also clear out some memory.
Well, set up SBP.
So that it points to this location
here.
So go ahead and load into yak's
the address of IVP.
So SBP points to the top of the
stack, which is going to point to
this. No bite for
us.
We go ahead and push that address
on top of the stack
and then we're pushing zero and so
zeros for the real time clock, if
you see there is a format for real
time on there.
And when you look that up in the
disassembled code, it ends up being
the number zero.
Go ahead and get the clock time.
All right, so now this should be
saved in our structure, which is on
top of the stack.
We got two bites in that particular
order.
And so now we're going to try and
print it off so
we can say move into X
and then we're going to reference
SBP plus.
And then we say my time
and we're going to get the nanoseconds.
So we'll grab the nanoseconds
and so this is just telling us a
specific offer offset
on there
and then I'll just copy these two
lines
because I'm going to change it from
nanoseconds to seconds.
And we need to load our format,
specify to
push that onto the stack
and call printf
so that I'll print it.
So we need to correct the stack
for our printer.
So we pushed on three parameters
so we can adjust it by 12.
And then in our previous one you see
that we pushed on
a bunch of things.
So if we go up and count, we've
got one, two,
three, four, five.
And so that ends up being.
14 and Hex, so we got
10 plus four
is 14.
And so we can see it gives us this
output.
I also have my mind, Ãâtzi, see,
so it should actually give me the
same output.
And so I can run.
And I can do both of them.
And we can see that the number of
seconds is similar, the number
of nanoseconds that takes some time
to execute this program and then
quit and and start executing this
one so that we can see that there
are a little bit different, which
is what we should have as a case.
So today, we saw an example using
structures and how we can take those
and reverse engineer
it from a C example
so that we can then use them in
assembly and define them in
assembly.
So in the future, we're going to
look at structures and unions and
we're going to look at how mallock
affects how they are created
and used.
If you have questions, you can email
me you in Edu
and you can find me on Twitter at
Milhouse 30.