Email or username:

Password:

Forgot your password?
Ken Shirriff

Another look inside the Intel 8086 microprocessor from 1978. This chip (and today's x86 computers) has "string" operations to efficiently copy or scan blocks of memory. They are implemented with microcode and a bit of special hardware. Let's see how this works. 🧵

12 comments
Ken Shirriff

Most people think of machine instructions as the lowest level of software, but many processors contain microcode. An instruction is broken down into micro-instructions. The 8086 has 21-bit micro-instructions; each executes a register move (source→dest) and an action in parallel.

Ken Shirriff

A string instruction performs a loop up to 64K times. Because the loop happens inside the processor, it's faster than writing the loop in assembly. The SI register points to the source, the DI register points to the dest, and the CX register counts. The details are complicated.

Ken Shirriff

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.

Ken Shirriff

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.

Ken Shirriff

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.

Ken Shirriff

For more about the implementation of the 8086's string instructions, including a detailed walkthrough of the microcode, see my blog post:
righto.com/2023/04/8086-microc

Greg Kemp

@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.

Amand Tihon

@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.

John Carlsen 4 Harris&Walz🇺🇸

@kenshirriff

Is this really microcode, or just assembly code?

I recall learning in 2001 that the AMD K8 internally translated opcodes to microcode, but the Wikipedia page isn't clear about which x86 device was first to implement it.

en.wikipedia.org/wiki/Microcod

"Earlier x86 processors are fully microcoded; starting with the Intel 80486, less complicated instructions are implemented directly in hardware. x86 processors implemented patchable microcode (patch by BIOS or operating system) since Intel P6 microarchitecture and AMD K7 microarchitecture."

@kenshirriff

Is this really microcode, or just assembly code?

I recall learning in 2001 that the AMD K8 internally translated opcodes to microcode, but the Wikipedia page isn't clear about which x86 device was first to implement it.

en.wikipedia.org/wiki/Microcod

"Earlier x86 processors are fully microcoded; starting with the Intel 80486, less complicated instructions are implemented directly in hardware. x86 processors implemented patchable microcode (patch by BIOS or operating system)...

JoJaSciPo

@kenshirriff

Fascinating! Thanks!!

reminds me horribly of that book The Soul of a New Machine:

en.wikipedia.org/wiki/The_Soul

That book confirmed all my worst suspicions of working in the USA and permanently killed any ambition to do so!😂

Steve

@kenshirriff
I don’t suppose you know of a teardown of the Intersil 6100 chip (also made by Harris)? Fond memories of using it in medical instrumentation—battery powered. Also with one of my fave books being Prosser/Winkel’s ‘The Art of Digital Design’ which builds a PDP-8 from scratch; it would be great to see how the chip did this.

archive.org/details/bitsavers_

Go Up