The x86 Jmp instruction

8086 image

I’ve been holding off on blogging about this for a while as well, and just want to get it out there.

About 6-7 months ago, I was doing some x86 thunking. As I was doing on the fly code generation, I hit a roadblock, which forced me into research mode for way too long.

The x86 didn’t have an instruction to do an immediate jump.

Essentially, I wanted a:

JMP #4C018030

I wanted it to be 5 bytes and I wanted to be done witht he project I was working on. It turned out that there is no such instruction. This is strange since they have immediate mode instructions for CALL and a few others. If they were trying to force the object code to be easily reolocatable, then they would have consistently made all IP mutators to be relative. They didn’t, so what gives?

I asked around and did a lot of research. Nobody really knows and the concern is not there. Almost all implementors do a BRANCH instruction which requires the destination addresss to be calculated.

I posted to USENET about this in June and got no real answer.

The surprising thing is that this is really a very very old instruction set (origins from the 70’s). I had serious doubts that they would eliminate an instruction that was so efficient and basic in order to force code to be position independent.

This is why I have quotes on my quotes page about the x86 instruction set. It always surprises me.

This entry was posted in General. Bookmark the permalink.

Leave a Reply

Your email address will not be published.