views:

56

answers:

2

I heard somewhere that conditional jump instructions in the x86 instruction set were limited to 256 bytes. (In other words, the jump could not go further than 256 bytes.)

Is this true? I have been writing logic involving JMP instructions to get around this. Is it necessary?

+5  A: 

IA32 supports 8 bit, 16 bit and 32 bit conditional relative jumps. x86_64 supports 8 bit and 32 bit conditional relative jumps. See Intel's Software Developer's Manuals.

Your assembler (or linker, if relocations are involved) should warn you if your label is out of range of the jump, anyway.


PS: In Real mode (and virtual-8086 mode), conditional jumps are restricted to offsets of +/-127.

caf
Aha! I knew I heard something about conditional jumps. Must have been from a real-mode assembly book.
George Edison
Thanks for answering, though - the code I'm writing will not be running in real mode.
George Edison
A: 

One small addendum to the other answer here (which is otherwise correct):

Your jump will never be "out of range". The particular encoding, and thus the decesion as to use a 32 bit, 16 bit, or 8 bit offset for any relative jump, will be made by your assembler. This is usually referred to as "instruction selection". In any case, given any 32 bit value of "eip" there is always some 32 bit signed displacement that, when added to "eip" will equal any arbitrary 32 bit address.

This means you can jump from anywhere in the program, to anywhere else, with a single jump.

The 8 bit and 16 bit forms of "jump/cc" just let you do that with fewer bytes in the instruction stream.

Scott Wisniewski
Note that that's not necessarily the case with x86_64, since there's no 64 bit relative jump. You would have to be doing something very odd to encounter such a situation, though. (It's also not the case in real mode, where conditional jumps *are* restricted to offsets of +/-127).
caf