Intel introduced the 8086 microprocessor in 1978 and it had a huge influence on computing. Ken Shirriff is reverse-engineering the 8086 by examining the circuitry on its silicon die and takes a look at how conditional jumps are implemented. Conditional jumps are an important part of any instruction set, changing the flow of execution based on a condition. Although this instruction may seem simple, it involves many parts of the CPU: the 8086 uses microcode along with special-purpose condition logic.
The 8086 processor has six status flags: carry, parity, auxiliary carry, zero, sign, and overflow. These flags are updated by arithmetic and logic operations based on the result. The 8086 has sixteen different conditional jump instructions that test status flags and jump if conditions are satisfied, such as zero, less than, or odd parity. These instructions are very important since they permit if
statements, loops, comparisons, and so forth. Sixteen is a large number compared to earlier CPUs: the 8080, 6502, and Z80 all had 8 conditional jumps, specified by 3 bits.
In machine language, a conditional jump opcode is followed by a signed offset byte which specifies a location relative to the current program counter, from 127 bytes ahead to 128 bytes back. This is a fairly small range, but the benefit is that the offset fits in a single byte, reducing the code size. For typical applications such as loops or conditional code, jumps usually stay in the same neighborhood of code, so the tradeoff is worthwhile.
The 8086’s microcode was disassembled by Andrew Jenner (link) from my die photos, so we can see exactly what micro-instructions the 8086 is running for each machine instruction… In brief, the conditional jump code (Jcond) gets the branch offset byte. It tests the appropriate condition and, if satisfied, jumps to the relative jump microcode (
RELJUMP
). TheRELJMP
code adds the offset to the program counter. In either case, the microcode routine ends when it runs the next instruction (RNI
).
Read the details in Ken’s blog here.