Ken Shirriff

The 8086 processor (1978) led to the hugely-popular x86 architecture. Internally, the 8086 uses microcode, running a tiny program for each machine instruction.
I'm reverse-engineering the chip from die photos and I can explain exactly how the 8086 microcode engine works.🧵 https://t.co/coxeuvvJQS

The idea of microcode is instead of implementing the processor's control circuitry with logic gates and circuits, you use another software layer. Microcode uses micro-instructions, simple instructions that generate hardware control signals and run in one step (clock cycle).

Here's part of the microcode for division. Each micro-instruction (yellow) moves a source register (S) to a destination (D). It also does an operation in parallel, e.g. subtraction (SUBT), left rotate (LRCY), conditional branch (NCY / no carry), (micro) subroutine return (RTN). https://t.co/0YySEh9gSm

Each micro-instruction is packed into 21 bits. Decoding circuitry generates low-level control signals from it. There are 6 types of micro-instruction. The optimized encoding format depends on the type. (F controls whether the instruction sets the condition flag register.) https://t.co/OSM9IISR2N

Mainframes started using microcode in the 1960s, but microcode took up too much space for the first microprocessors. The 8086 was the first Intel chip to use microcode (I think); microcode took up a large fraction of the chip. Lots of optimizations were needed to make it fit. https://t.co/uh6Hw6hqHa

Here's a closeup of the microcode on the die. The address register holds a 13-bit micro-address. Column selection circuitry selects one column of the microcode ROM. There are 512 micro-instructions, stored four per column to improve the layout. https://t.co/VOgdgLvZ5z

Zooming in, you can see individual transistors in the microcode ROM. The silicon doping pattern defines the 0's and 1's. A few years ago, Andrew Jenner disassembled the 8086 microcode from my die photos. See his blog post to see the complete microcode.
https://www.reenigne.org/blog/8086-microcode-disassembled/ https://t.co/JOpm6V9VrQ

8086 supports many addressing modes through the second byte of instructions, the ModR/M byte. These are implemented by subroutines in the microcode. The "Translation ROM" (die photo below) holds the micro-addresses for subroutines. https://t.co/9UeuZV2GMC

The microcode address register steps through microcode with a 13-bit address: 8 bits from the instruction, 4 sequential bits, and an extra X bit. It has a register to hold the subroutine return address. Multiplexers select the address for call/return/jump/interrupt/etc. https://t.co/P096whrvrx

To summarize, you might think that machine instructions are what processors execute. But microcode forms a lower layer: the processor runs multiple micro-instructions to implement each machine instruction. Microcode simplifies processor design making much of it software.

Here's a die photo of the 8086 using the color scheme from Apple's M1 chip. It amuses me to parody Apple's gradient by applying it to vintage chips. https://t.co/EVFqrbtCCY

For more details on 8086 microcode, see my blog post:
https://www.righto.com/2022/11/how-8086-processors-microcode-engine.html

Sat Dec 03 19:18:58 +0000 2022