Some Technical Details on on Compares and Jumps
The 80X86 encodes all conditional bytes with an opcode and a displacement
byte, since most jumps are to nearby locations. The CPU:
There will be times when the short jump will not be far enough. When
that happens, you can just use the JUMP instruction. The assembler
will assume that you want a two-byte displacement. (To prevent
that, you must put the word SHORT in front of the label.)
- Fetches the instruction and the IP is updated to point to the next
- The flags are checked, and if the condition holds, the CPU
sign-extends the displacement to a word,and then does
IP := IP + displacement.
- The CPU is now ready to fetch the correct next instruction,
whether or not the jump was taken. The assembler will automatically
calculate the displacement for you.
Sometimes you will get a "jump out of range" error message.
Replace your instruction (such as):
This converts a two-byte instruction into two instructions with
a total of five bytes. Note that this is a jump around a jump
and is not considered good style, but it is the only way for
you get cure the "jump out of range" error message.
The Intel manual states:
"The target instruction is specified with a relative offset (a signed offset relative to the current value of the instruction pointer in the EIP register).
A relative offset (rel8, rel16, rel32 is generally specified as a label in assembly code, but at the machine
level, it is encoded as a signed, 8-bit
or 32-bit immediate value, which is added to the instruction pointer. Instruction
coding is most efficient for offsets of -128 to +127. If the operand-size attribute is 16, the upper two bytes of the EIP register are cleared to 0s,
resulting in a maximum instruction
pointer size of 16 bits.
Additionally, there loop instruction has a conditional version that allows you to combine
two tests (checking the the zero flag) into one:
- loopew (32-bit)
- looped (32-bit)
- loopzw (32-bit)
- loopzd (32-bit)
©2004, Gary L. Burt