13 hours 15 minutes
Hello. This is Dr Miller, and this is Episode 14.11 of Assembly.
Today. We're going to given in line assembly example.
So in line assemblies Example.
So our problem to be solved is that we need to capture the time we're going to use the time stamp counter.
And so we're gonna use the RD TSC Assembly Command, and this command store is the result in E, d, X and E X.
And so we're going to save that to a Q word, and then we're gonna print the result. And so what we're gonna do is we're actually gonna write to programs today,
So the 1st 1 is our assembly version of the code.
So in that
we're going to just give an example of how to do all of this. So well,
I use a Q word, and that's for our result.
You've got our format
we're going to use, so this is a long
unsigned, so we're gonna use
that format, so l l u
we're also going to use print half
so down here, we're going to call the R D T S C
command, and again that's going to save it in e D, X and V X.
And so here I'm going to move into bbx our
address of our where we want to store the data.
And then we're gonna move into that location and ebx the value of V A X. It's that has the bottom half ad for
TVX because it's eight bites and then move into location ebx
e d. X. So that's our second register.
And now we got to set up this stuff for print F.
So we're gonna move into yea x A plus
Push the X and then move into e x
A. It's reloading the data from our variable a
pushing those onto the stack so that we can call print F move
push the format
and then we'll go ahead and call
And then we have to correct our stacks. Add yes, p
So this should
give us what we want.
All right, so it looks like we have an air. Let's see if we can find that
I forgot to put
ex turn in here.
All right, so let's rebuild that.
All right, so we can see that we get the time.
So now let's look at how we would do this in C.
So some of it's going to be easier. Some will be more difficult.
So we'll include the standard Io library.
So we can do print off
the standard live directory
for some normal functions, and we have our end
and then we have to declare our variables. So we're gonna use unsigned
long, long to do our cue word.
Go ahead and set time 20
and then we're going to,
do our assembly. So I'm gonna use sm
And then this is where we're going to put our code.
Have a couple more pieces here. So go ahead and get those set up.
Um, and then we got the end of our code there.
All right, so this is gonna be
All right? So to emulate what we did,
we're going to do r d t C
again. We got to put new lines in here if we're going to use them,
and then we'll make another line
putting quotes so that we make this a little bit readable
for what we're doing.
So we're gonna end up with our output is going to be
we're going to use a memory just for this.
And the variable is going to be time. So it's our time, Variable, We're not gonna have any input and we'll figure out what our clubbers are.
So we should know that from the RTs see, it's gonna use yea x
and you d x
so we know that all clobber those
and I'm gonna end up using some or in here.
So first of all, because its memory address, what I'd like to do is I'd like to load that memory address
into a register, So I'm actually going to use e b x toe load in
my output, which is percent zero again. Put a new line in here.
I think it'll be easy to
Ah, yank and copy. So, Yankee, why for Yank p for put metal copy online and put it.
And so now we need to save our values. So we're gonna go ahead and do move
into the value pointed to by EBX, right? Because we got an address for it here.
And the reason we have to use Elia's cause by default, right time is gonna be put on the stack
and so we want to load that memory address in.
So go ahead and save the X there.
And then we can go down here and
copy again. So let's add for TB X like we did in our main one.
So the ad be x
and then again, we'll have to save our data,
so move into the value pointed to by the new part of ebx
VD X rights. That's the top half of our register that we have.
And so now we have gone ahead and modified ebx. And so you want to tell it that by the way, EBX
has been Colomb Erred has been destroyed.
Then at the end, we're gonna print off our time and we're just use regular print f
what time is, and then use my same format.
Got a nice new line in there and we get it.
so now we should be ready to build that. So,
let's get it here. So we want to do minus M 32. So for 32 bit
on minus man as, um equals Intel to say that we're using Intel syntax
we're gonna do may not see.
Looks like I spelled
vole a tall wrong.
There we go.
Oh, and then I forgot my argument for my print up here.
All right, so we got to put our time
and by default think it's created in a doubt out. So I'm gonna run my two side by side,
and so I'll do love and, uh
and I didn't quite get him lined up, but we can see that they are pretty close to each other,
right? So one of the things with the RTs r d t s c. Is that it's counting clock cycles from the very beginning. So if your clock is running at four billion cycles a second, you get a somewhat accurate measurement of time,
depending on a lot of different things that have changed with
see, if you use going up and down in speed and
multi processors sort of make that interesting.
But we can see that there are some benefits to each one of these. So, for example,
if I look at
my assembly code, it's probably a lot easier to understand how to load this memory address in and then do this right. So the
the actual time stamp was a lot easier to do in here,
But then when we go to print off, so this might be a lot more work
then if we go back to our
main program and look
well, if I want to call print f right, I can very easily do that in one line. And it's a lot simpler,
um, than the in line assembly. And so the in line assembly.
It is somewhat difficult because that, well, these new lines in and we have to
make sure that
we figure out what we're collaborating, what we're doing with this and that. And so each one of them has its own benefits in its own drawbacks. And so you just have to choose the correct one
for how you are programming.
So today we saw on in line assembly example and looking forward, we're gonna do some or combination of assembly and see together and maybe a little bit more easier
a manner. So if you have questions, you can email me Miller M J u N K I e t you and you can find me on Twitter at Melas 30
How to Use GDB (BSWJ)
The GNU Debugger (GDB) is one of the most commonly-used debugging tools in the world. ...
Certificate of Completion Offered
How to Use IDA (BSWJ)
The IDA is used throughout the IT and cybersecurity industries by exploit developers, vulnerability analysts, ...
Certificate of Completion Offered