13 hours 15 minutes
Hello. This is Dr Miller, and this is Episode 14.7 of Assembly.
Today, we're going to create a jump table, an assembly,
So assembly jumped table.
So one of the things that were going to do is we're actually going to define data in the code section, and I'll show you had to do that.
And then we're going to write a program that calculates whose turn it is based on a schedule based on the day of the month.
So we're gonna alternate between the three persons, a person, A, B and C.
So if the module is zero, it's gonna goto the first person. If it's one that goes to the second person, if it's too, it goes to the third person.
So I've already went ahead and created our project here.
And so at the top, we're gonna create a couple different prompts that we're going to have.
So the 1st 1
the day of the month,
make sure we know, terminate it and then we have one for each of our persons.
Put a nice new line after it,
do some copy pasting here so that we don't have to type the same thing over and over again.
Yeah, a B and we got C. And then we're gonna have one more,
and we'll put none.
And we'll do a sanity check on that one.
All right, so then we're going to go into our code section here, and then we're going to do Ah,
um, move our first prompt in there and then printed. So movie X text
all print spring
call read. And so we call read. Ain't we know that
yea X then has our value.
And so what we're gonna use here,
then is we're gonna do some division on that. So movie see? Ex
three. So that's gonna be our module iss, um,
operator that we're gonna run on movie D X zero got a zero that out, and then we'll go and divide what's in e X
by E. C X. And then remember, Edie X has are a module ISS,
so we'll just copy that
And so we might want to do a little comparison in here later.
Um, is making sure that our modules is correct. But here we'll just,
so we'll jump greater than or equal to, so we shouldn't get anything greater than that, but just to make sure,
I'll just call it default. Er so down here, we're gonna create our default label,
so we'll use the other value in that. And so then, with all of these, um, when we're done,
we're going to move. We'll call Prince String
to print off the label to get set. So in each of our cases, we're going to set a label.
No, go ahead and call print, string and call Print
New Line at the very end so I could put a jump done here, but it's just gonna fall through, so there's no use doing that.
So now we're assuming that we've gotten a number. Um, that is what we want. And so now it's time Teoh will build our table, and then we'll do our comparisons on that.
in here, I'm going to
just call a table. You can call it whatever you want, but we can actually define things, So I'm gonna say X
why? And metabolize insulin look nice
and you can pick whatever names you want here. But these are also going to be labeled names,
and so it's gonna have those addresses inside of there. So I say X
and I'm going to say move, Yea X person One
Right. So we have our done label so that it will go ahead and do our print.
So now we'll define why
Bouvier X p two
um done on dzi
movie A XP three.
So we have our labels here, and so when we define this table, this is going to be each one of these is a pointer to one of these
labels inside of there.
we will do our calculation. We will then jump to the location, pointed to buy this and then these each point to a very specific
where we'll start executing code.
So now it's time to figure out our table offset. So first, we're going to move into E v X,
the offset of the table so we know where that is.
Um, I'm gonna move into yea X the number forces how big each entry in the table is.
So this is very specific to 32 bit. Um, if it was 64 bit, we would be doing eight.
But a 32 bit pointer is going to be four bites. And so that's why that's coated in there.
And then we're going to multiply by CCX
so easy X should have our number. It should be 01 or two
And so we multiply that by four we'll get an offset of either zero for eight for our offset.
So then we can add that
um TB X. So we'll just use e v X
because that has the offset of our table. And then we're getting the offset of what entry did we want inside of there. So we're gonna add E X
and then we'll go ahead and jump to EBX and we could have done it either way. Really Doesn't matter. Could have taken the offset and added the table or vice versa. Either way would have worked.
But what we're doing here is we're gonna jump to EBX. But we want to jump to the location pointed to by EBX. So we had our address of our table so well, then get the data either having the pointer for X, the pointer for why? Or the pointer for Z.
And so that is how we would implement that.
So now we should be done.
So if it's the first of the month, it's person be. If it's the second month, if it's 1/3 of the month,
I'm depending on your definition of when a month starts. So most people would use the numbers 12 or three,
um, for the days of a month, not zero through the number minus one.
And so then we can see that if we pick a higher number of Solis A 15
Well, that mod three is zero. So that would be person a or if we did 17
that would be mod. Mod three would give us two. And so that would be person. See,
So today we created a jump table in assembly and we defined our pointers inside the data section. We could have put inside the code section. We could have put them in the data section,
but it makes more sense. And it aligns with how we typically would do it. Um, when you would see compiler generated code.
So, looking forward, we're gonna talk about function pointers.
If you have questions, you can email me Miller MJ at you and Keita et you, and you can find me on Twitter at Milhouse 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