Jump Table Example
Video Activity
Join over 3 million cybersecurity professionals advancing their career
Sign up with
Required fields are marked with an *
or
Already have an account? Sign In »

Course
Difficulty
Beginner
Video Transcription
00:00
Hello. This is Dr Miller, and this is Episode 14.7 of Assembly.
00:06
Today, we're going to create a jump table, an assembly,
00:09
So assembly jumped table.
00:12
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.
00:18
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.
00:26
So we're gonna alternate between the three persons, a person, A, B and C.
00:31
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.
00:41
So I've already went ahead and created our project here.
00:44
And so at the top, we're gonna create a couple different prompts that we're going to have.
00:49
So the 1st 1
00:54
enter
00:56
the day of the month,
01:02
make sure we know, terminate it and then we have one for each of our persons.
01:12
Put a nice new line after it,
01:17
do some copy pasting here so that we don't have to type the same thing over and over again.
01:23
Yeah, a B and we got C. And then we're gonna have one more,
01:32
and we'll put none.
01:36
And we'll do a sanity check on that one.
01:38
All right, so then we're going to go into our code section here, and then we're going to do Ah,
01:44
um, move our first prompt in there and then printed. So movie X text
01:49
all print spring
01:55
call read. And so we call read. Ain't we know that
02:00
yea X then has our value.
02:02
And so what we're gonna use here,
02:05
then is we're gonna do some division on that. So movie see? Ex
02:09
three. So that's gonna be our module iss, um,
02:14
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
02:23
by E. C X. And then remember, Edie X has are a module ISS,
02:29
so we'll just copy that
02:35
into CCX.
02:53
And so we might want to do a little comparison in here later.
02:58
Um, is making sure that our modules is correct. But here we'll just,
03:02
um
03:04
so we'll jump greater than or equal to, so we shouldn't get anything greater than that, but just to make sure,
03:12
I'll just call it default. Er so down here, we're gonna create our default label,
03:22
so we'll use the other value in that. And so then, with all of these, um, when we're done,
03:30
we're going to move. We'll call Prince String
03:37
to print off the label to get set. So in each of our cases, we're going to set a label.
03:42
No, go ahead and call print, string and call Print
03:46
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.
03:53
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.
04:05
So
04:06
in here, I'm going to
04:10
just call a table. You can call it whatever you want, but we can actually define things, So I'm gonna say X
04:17
why? And metabolize insulin look nice
04:21
and you can pick whatever names you want here. But these are also going to be labeled names,
04:27
and so it's gonna have those addresses inside of there. So I say X
04:31
and I'm going to say move, Yea X person One
04:36
jump done.
04:40
Right. So we have our done label so that it will go ahead and do our print.
04:43
So now we'll define why
04:46
Bouvier X p two
04:49
um done on dzi
04:54
movie A XP three.
04:58
Um, done.
05:00
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
05:08
labels inside of there.
05:11
So
05:12
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
05:18
memory location
05:20
where we'll start executing code.
05:23
So now it's time to figure out our table offset. So first, we're going to move into E v X,
05:30
the offset of the table so we know where that is.
05:33
Um, I'm gonna move into yea X the number forces how big each entry in the table is.
05:40
So this is very specific to 32 bit. Um, if it was 64 bit, we would be doing eight.
05:45
But a 32 bit pointer is going to be four bites. And so that's why that's coated in there.
05:50
And then we're going to multiply by CCX
05:55
so easy X should have our number. It should be 01 or two
06:00
And so we multiply that by four we'll get an offset of either zero for eight for our offset.
06:08
So then we can add that
06:11
Yea x
06:13
um TB X. So we'll just use e v X
06:17
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
06:27
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.
06:38
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.
06:53
And so that is how we would implement that.
06:57
So now we should be done.
07:04
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,
07:11
I'm depending on your definition of when a month starts. So most people would use the numbers 12 or three,
07:16
um, for the days of a month, not zero through the number minus one.
07:21
And so then we can see that if we pick a higher number of Solis A 15
07:27
Well, that mod three is zero. So that would be person a or if we did 17
07:32
that would be mod. Mod three would give us two. And so that would be person. See,
07:45
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,
07:56
but it makes more sense. And it aligns with how we typically would do it. Um, when you would see compiler generated code.
08:05
So, looking forward, we're gonna talk about function pointers.
08:09
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
Up Next
Function Pointers
Function Pointers Example
Inline Assembly
Inline Assembly Example
Assembly with C
Similar Content