Site Logo

Jump Instructions

Website

Home | Previous | Next

Jump Instructions - Flags are NOT set.

These instructions do NOT set the Z, S or O flags but conditional jumps use the flags to determine whether or not to jump.

The CPU contains a status register - SR. This contains flags that are set or cleared depending on the most recent calculation performed by the processor. The CMP compare instruction performs a subtraction like the SUB command. It sets the flags but the result is not stored.

The Flags - ISOZ

  1. ZERO - The Z flag is set if the most recent calculation gave a zero result.
  2. SIGN - The S flag is set if the most recent calculation gave a negative result.
  3. OVERFLOW - The O flag is set if the most recent calculation gave a result too big to fit a register.
  4. INTERRUPT - The I flag is set in software using the STI command. If this flag is set, the CPU will respond to hardware interrupts. The CLI command clears the I flag and hardware interrupts are ignored. The I flag is off by default.

The programmer enters a command like JMP HERE. The assembler converts this into machine code by calculating how far to jump. This tedious and error prone taks (for humans) is automated. In an 8 bit register, the largest numbers that can be stored are -128 and +127. This limits the maximum distance a jump can go. Negative numbers cause the processor to jump backwards towards zero. Positive numbers cause the processor to jump forward towards 255. The jump distance is added to IP, the instruction pointer.

To understand jumps properly, you also need to understand negative numbers.

COMMANDS
EXAMPLES
OP
Assembler Machine Code Explanation
JMP
JMP HERE C0 25 Unconditional jump. Flags are ignored.
Jump forward 25h RAM locations.
JMP
JMP BACK C0 FE Jump Unconditional jump. Flags are ignored.
Jump back -2d RAM locations.
JZ
JZ STOP C1 42 Jump Zero. Jump if the zero flag (Z) is set.
Jump forward +42h places if the (Z) flag is set.
JZ
JZ START C1 F2 Jump Zero. Jump if the zero flag (Z) is set.
Jump back -14d places if the (Z) flag is set.
JNZ
JNZ FORWARD C2 22 Jump Not Zero. Jump if the zero flag (Z) is NOT set.
Jump forward 22h places if the (Z) flag is NOT set.
JNZ
JNZ REP C2 EE Jump Not Zero. Jump if the zero flag (Z) is NOT set.
Jump back -18d places if the (Z) flag is NOT set.
JS
JS Minus C3 14 Jump Sign. Jump if the sign flag (S) is set.
Jump forward 14h places if the sign flag (S) is set.
JS
JS Minus2 C3 FC Jump Sign. Jump if the sign flag (S) is set.
Jump back -4d places if the sign flag (S) is set.
JNS
JNS Plus C4 33 Jump Not Sign. Jump if the sign flag (S) is NOT set.
Jump forward 33h places if the sign flag (S) is NOT set.
JNS
JNS Plus2 C4 E2 Jump Not Sign. Jump if the sign flag (S) is NOT set.
Jump back -30d places if the sign flag (S) is NOT set.
JO
JO TooBig C5 12 Jump Overflow. Jump if the overflow flag (O) is set.
Jump forward 12h places if the overflow flag (O) is set.
JO
JO ReDo C5 DF Jump Overflow. Jump if the overflow flag (O) is set.
Jump back -33d places if the overflow flag (O) is set.
JNO
JNO OK C6 33 Jump Not Overflow. Jump if the overflow flag (O) is NOT set.
Jump forward 33h places if the overflow flag (O) is NOT set.
JNO
JNO Back C6 E0 Jump Not Overflow. Jump if the overflow flag (O) is NOT set.
Jump back -32d places if the overflow flag (O) is NOT set.

The full 8086 instruction set has many other jumps. There are more flags in the 8086 as well!

Legal Destination Labels

here: A nice correct label.
here:: Not allowed Only one colon is permitted.
1234: Not allowed. Labels must begin with a letter or '_'.
_: OK but not human friendly.
here Destination labels must end in a colon.

Some of these rules are not strictly enforced in the simulator.

Home | Previous | Next

© C Neil Bauers 2003