Here's what the microcode looks like for the string move instruction: the main code, a micro-subroutine to check the CX register, and a micro-subroutine to handle interrupts. Each micro-instruction has a move on the left and an action on the right.
Top-level
Here's what the microcode looks like for the string move instruction: the main code, a micro-subroutine to check the CX register, and a micro-subroutine to handle interrupts. Each micro-instruction has a move on the left and an action on the right. 7 comments
Arithmetic and logic instructions use the ALU (Arithmetic/Logic Unit). But incrementing/decrementing the memory pointers doesn't use the ALU. Instead, it uses a special adder that calculates memory addresses. A "Constant ROM" holds the values (-6 to +2) that need to be added. For more about the implementation of the 8086's string instructions, including a detailed walkthrough of the microcode, see my blog post: Thanks to Andrew Jenner for disassembling the microcode. @kenshirriff Fun with MOVS: x86 supports self-modifying code, but what about self-modifying _instructions_? Turns out with MOVS you could do self-modifying instructions. @kenshirriff Thank you! I love your articles on the 8086! Just one remark: the 20 bit address bus gives access to 1 megabyte, not 4. |
Some hardware helps the microcode. Latches remember the "repeat" prefix. Hardware lets the microcode test conditions, e.g. is CX zero, is there a repeat prefix, is the loop exit condition satisfied, is there an interrupt. Photo shows the chip circuitry for 16 conditions.