13 hours 15 minutes
Hello. This is Dr Miller and this is Episode 14.3 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 see, we can see the structure, times, beck,
and it's called Start, and we'll go ahead and see that
we're gonna call clock underscore, get time. And that's going to be used to fill that structure
with the data about the number of seconds in the number of nanoseconds. And then we go ahead and print it off inside of this
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 the time using the get clocked underscore get time.
And then we're gonna print it out just like we do in the example.
Alright, so I've already started this.
So what we're gonna want to do is we're gonna define our structure.
So here we used 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 got TV 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 rez de one,
and then the next part is the nanoseconds.
And for that will also
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 saying of our structure, we're also going to be printing something out so we'll define our format.
The time is, and we use L. D
for our formats bus fire for seconds,
the same thing for name of seconds
here, we're going to be using a couple of different functions, so we'll just declare those ex turns
so they got print F
and get our clock.
Is this called clock underscore? Get time.
All right. And so I'll put it in a few things. When we're the bugging, we'll get to see it. So, for example, we're gonna push
known values so we can see it on the stack.
Also clear at some memory,
we'll set up E v p
so that it points to this location here.
So go ahead and load into yea x.
The address of E V P. C E Beeby points to the top of the stack,
which is gonna point to this No bite for us.
We'll 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,
um, 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 gonna try and print it off so
we can say move into yea X, and then we're going to reference E v P
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 off offset on there.
And then I'll just copy these two lines
because I'm gonna change it from nanoseconds two seconds.
Then we need to load our formats. Best fire
pushed onto the stack
and call print F.
It's a little print it. So we need to correct the stack
for our print f. 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
And so that ends up being
14 in Hex. So we got 10
plus in a four is 14
and so we can see it gives us this output. Um, I also have my main dot c.
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. It takes some time to execute this program and quit and start executing this one.
So they're going to see that they're a little bit different, which is what we should have is the 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 gonna look at structures and unions, and we're gonna look at how Malik affects how they are created and used.
You have questions you can email me Miller M J U N K D i e d u. And you can find me on Twitter at Milhouse 30