The x86 CPU: From 4004 to 486
Hacker News

The x86 CPU: From 4004 to 486

Comments

We already covered the main ideas behind Real Mode & Protected Mode in one of our previous posts. This article will build on those concepts and take a deeper look at the history and evolution of the x86 family of CPUs.

But rather than simply looking at the innovations introduced with each new chip, we need to understand how the architecture accumulated over time, from its origins in the early 70s up until the launch of the 486.

Every time a new student starts learning x86 assembler with us, it's not rare to hear them complain that many aspects of the instruction set look arbitrary. An accumulator that some instructions insist on, a base register that is the only one allowed to point at memory, a parity flag nobody seems to use, and an addressing scheme that adds two 16-bit numbers together in a very strange way.

The majority of teaching resources out there will help you write your first lines of x86 code, assemble it, link it, and as proceed as soon as the output matches what you were expecting. I try to always explain the evolution of the x86 family of CPUs, so every aspect of our code makes a little bit more sense.

None of these things are arbitrary, of course. Each one is a decision someone made under pressure, usually to keep old software running on a new chip. If you want to really understand x86 (and especially if you want to program a 486 under DOS), the best place to start is not the 486 manual. It's the story.

Here is the family tree we're going to walk through:

Year Chip Width Addr. space What it added that still shows up in x86
1971 4004 4-bit 4 KB prog. ROM Intel's first CPU, for a Busicom calculator
1972 8008 8-bit 16 KB Register set A, B, C, D, E, H, L; little-endian order and a parity flag, both inherited from the Datapoint 2200 terminal it was designed for
1974 8080 8-bit 64 KB 16-bit register pairs (BC, DE, HL), a real stack pointer, a separate 256-port I/O space with IN /OUT
1976 8085 8-bit 64 KB One 5 V supply; address and data multiplexed on the same pins to save pins
1978 8086 16-bit 1 MB Segmentation, a prefetch queue, 16-bit registers that contain the 8080's 8-bit ones
1979 8088 16-bit inside, 8-bit bus 1 MB The cheaper version IBM chose for the 1981 PC
1982 80286 16-bit 16 MB Protected mode with segment descriptors and privilege rings
1985 80386 32-bit 4 GB 32-bit registers, paging, virtual 8086 mode
1989 80486 32-bit 4 GB On-chip cache and FPU, a 5-stage pipeline

A table like this makes the evolution look neat and planned. It wasn't. Between these rows there are cancelled projects, a customer who walked away from its own chip, a stopgap that was supposed to last a couple of years, a sales campaign, a keyboard controller wired into the address bus, and a lawsuit.

Let's travel back to 1969 and see how it all happened!

A Calculator Chip: The 4004

The story starts with a Japanese calculator company. In 1969, Busicom asked Intel (then a young memory company) to build a set of custom chips for a new printing calculator. Instead of designing many single-purpose chips, Intel's team proposed something more general: a small programmable processor that would run the calculator's logic from ROM.

The result was the 4004, released on November 15, 1971, and designed by Federico Faggin, Ted Hoff, Stanley Mazor, and Masatoshi Shima. It had 2,300 transistors, ran at about 740 kHz, and could address 4 KB of program ROM.

The most important line in the 4004's story is not technical, though. Busicom had paid for the design and owned the rights. When Busicom ran into financial trouble in 1971, Faggin convinced Intel's CEO Bob Noyce to lower the chip's price in exchange for Intel getting out of the exclusivity deal. Intel paid back Busicom's $60,000 development costs and won the right to sell the chip to anyone (outside the calculator market).

That deal is why "a microprocessor" became something Intel could sell, rather than a part buried inside one calculator.

The Terminal That Didn't Want Its CPU: The 8008

At almost the same time, a second customer walked through Intel's door. In late 1969, Computer Terminal Corporation (CTC, later called Datapoint) asked Intel to build a chip for a programmable terminal called the Datapoint 2200.

This detail matters a lot: Intel did not design the instruction set of this chip. CTC's engineers Victor Poor and Harry Pyle did. They had already built the Datapoint 2200's processor out of dozens of discrete TTL chips, and they wanted Intel to squeeze that same design onto one piece of silicon.

Intel was slow. Texas Instruments also tried to build the chip, but its samples were buggy and rejected. Meanwhile, CTC shipped the Datapoint 2200 in 1970 with its TTL processor anyway, and later moved on to a faster design. In the end, CTC voted to walk away from the project and leave the design to Intel instead of paying the $50,000 contract. Intel renamed it the 8008 and released it in April 1972 with 3,500 transistors and 16 KB of addressable memory.

So the ancestor of every x86 chip was designed by a terminal company, for a terminal, and then rejected by that terminal company. And two of the terminal's habits are still inside your PC today.

Why x86 is Little-Endian

The Datapoint 2200 processed numbers one bit at a time (a bit-serial design). If you're adding two numbers one bit at a time, you want to start with the lowest bit, because that's where the carry starts. So it made sense to store the lowest byte first in memory. The 8008 copied the Datapoint's design, the 8080 kept compatibility with the 8008, and the 8086 kept compatibility with the 8080.

Stephen Morse, the architect of the 8086, put it this way in his history of the early Intel processors: "This inverted storage, which was to haunt all processors evolved from the 8008, was a result of compatibility with the Datapoint bit-serial processor."

That's why, on your 486 (and even in a more modern Core i9), this instruction:

mov DWORD ptr [buffer], 12345678h

...stores the bytes 78 56 34 12 in memory.

Why x86 Has a Parity Flag

The second habit is the parity flag (PF), which tells you if the result of the last operation had an even number of 1 bits. It's one of those flags that beginners look at and wonder who on earth needs it. The answer is: a terminal does!

Morse again: "This permits testing for transmission errors, an obviously useful function for a CRT terminal." Data arriving over a serial line often carried a parity bit, and the Datapoint needed a fast way to check it. Fifty years later, PF is still bit 2 of the x86 FLAGS register.

The 8080 and the Birth of the PC Hobby

The 8008 was slow and awkward, so Intel designed a much better successor. The 8080 was released in April 1974, with Federico Faggin as its primary architect and Masatoshi Shima on the detailed design. It had about 4,500 transistors, ran at 2 MHz, and could address 64 KB of memory.

The 8080 was not binary compatible with the 8008, but it kept the same register set and the same "flavor." More importantly, it added several things you will recognize as an x86 programmer:

  • Register pairs: B and C could be used together as the 16-bit pair BC, and the same for DE and HL
  • The HL pair as the main way to point at memory (MOV A, M reads the byte at address HL)
  • A real 16-bit stack pointer
  • A separate I/O space with 256 ports, accessed with IN and OUT

That separate I/O space is the reason why, many years later, VGA registers live at "port 3C8h" instead of at a memory address.

The 8080 powered the Altair 8800 and became the standard CPU for CP/M, the most popular operating system for small business computers in the late 70s. Suddenly, there was a lot of 8080 software out there.

And then Intel got some serious competition. Faggin and Shima left Intel and went to Zilog, where they built the Z80: a chip that could run 8080 machine code, but was faster, cheaper to build a computer around, and had more instructions. The Z80 started eating Intel's market.

The 8085: A Quiet Hint of What Was Coming

Intel's answer was the 8085, released in March 1976. The "5" in the name refers to its biggest selling point: it needed a single +5 V power supply, while the 8080 needed +5 V, -5 V, and +12 V. To fit everything into a 40-pin package, the 8085 also multiplexed its bus: the same eight pins carried the low byte of the address first, and then the data.

Remember this trick, because the 8086 uses it too.

There's a lovely footnote here: the 8085 had 12 new instructions, but Intel made a last-minute decision to document only 2 of them. The reason? To keep things simple for the next chip, which was already being designed. That chip was the 8086.

The Stopgap That Took Over the World: The 8086

In the mid 70s, Intel's big bet for the future was not the 8086. It was the iAPX 432, a very ambitious processor designed with object-oriented programming and high-level languages in mind. The 432 was late, and with the Z80 taking customers away, Intel needed something to sell in the meantime.

So, in May 1976, Intel started the 8086 project as a temporary product. Stephen Morse was the principal architect, Jim McKevitt and John Bayliss were the lead hardware engineers, and Bill Pohlman managed the project. The 8086 was released on June 8, 1978.

The brief was clear: the new chip had to address more than 64 KB, do 16-bit arithmetic, and (this is the important part) make it easy for existing 8080 software to move over.

Source Compatibility, Not Binary Compatibility

The 8086 cannot run 8080 machine code. Instead, Intel aimed for source compatibility: you could take your 8080 assembly program and translate it, line by line, into 8086 assembly. Intel even shipped a translator called CONV86 (available from 1978) to do this automatically.

Morse described the goal like this: "the 8080 register set and instruction set appear as logical subsets of the 8086 registers and instructions." For that translation to work, every 8080 register needed an obvious home in the 8086. And this is where the 8086's register names come from:

Here's a tiny 8080 routine and its 8086 translation side by side:

; 8080                ; 8086
LXI H, buffer         mov bx, offset buffer ; HL becomes BX
MOV A, M              mov al, [bx]          ; A becomes AL
INX H                 inc bx
ADD M                 add al, [bx]

Now some of the "weird" things about x86 suddenly make sense:

  • AX is the accumulator because 8080's A became AL. That's why MUL, DIV, IN, and OUT insist on using it, and why many instructions have shorter encodings when they use AL/AX.
  • BX is the base register because the 8080's memory pointer HL became BX. That's why, in 16-bit code, BX is the only one of AX, BX, CX, DX that can point at memory.
  • CX is the count register (used by LOOP, REP, and shifts) and DX is the data register (used for I/O port numbers and the high half of 32-bit results).
  • The 8080's flags byte became the low byte of the 8086's FLAGS register, and the instructions LAHF and SAHF exist just to move that 8080-shaped byte in and out of AH.

Have you ever wondered why the 8086 numbers its registers in the order AX, CX, DX, BX (0, 1, 2, 3) inside instruction encodings, instead of the obvious A, B, C, D? It follows the 8080's order of register pairs: BC, DE, HL. Once A is placed first, BC becomes CX, DE becomes DX, and HL becomes BX.

And what does the "X" mean? According to Morse himself, nothing special. It was simply an arbitrary letter combining the "H" and "L" halves into one 16-bit register (as told to Vladimir Keleshev).

Segmentation: Reaching 1 MB with 16-bit Registers

The second big requirement was memory. Intel wanted 1 MB of address space, and that needs 20 address bits. But the 8086's registers were only 16 bits wide. Morse's solution was segmentation. The chip has four segment registers (CS, DS, SS, and ES), and every memory access combines a segment with a 16-bit offset:

$$ \text{address} = \text{segment} \times 16 + \text{offset} $$

Multiplying by 16 is just a shift of 4 bits to the left. For example, if we want to write to pixel (160, 100) in VGA mode 13h, which lives at segment A000h:

mov ax, 0A000h
mov es, ax ; segment = A000h
mov di, 320*100 + 160 ; offset = 7DA0h
mov byte ptr es:[di], 15 ; physical address = A0000h + 7DA0h = A7DA0h

Why 16 and not something bigger, like 256? Morse explained that with 8 bits of shift, "segments would be forced to start on 256-byte boundaries, resulting in excessive memory fragmentation." Segmentation was cheap (a small adder in the chip) and it worked very well with the source-compatibility goal: an 8080 program expected a 64 KB world, so you could give it one segment and it would run unchanged, wherever in memory that segment happened to be.

But it also created a rule that haunted every DOS programmer for the next 15 years:

That rule is why C compilers for DOS had near , far , and huge pointers, and memory models with names like tiny, small, compact, and large. It's also why mode 13h is so beloved: 320 × 200 = 64,000 bytes, which fits in one segment!

Operation Crush and the 8088

The 8086 was not an instant hit. Motorola's 68000 and Zilog's Z8000 were more elegant 16-bit designs, and many engineers preferred them. Intel's response was a sales campaign called Operation Crush, launched in a meeting in December 1979. Instead of selling the 8086 on raw specs, Intel sold it as a complete solution: development tools, support chips, documentation, and support. The goal was 2,000 "design wins" (products using the chip) in one year. They got nearly 2,500.

One of them was a small project inside IBM in Boca Raton.

A year after the 8086, Intel had released the 8088 (June 1, 1979). Internally it's the same 16-bit processor, but with an 8-bit external data bus. Every 16-bit memory access takes two bus cycles, so it's slower. But an 8-bit bus meant you could build the computer with cheap, plentiful support chips designed for the 8085.

Intel also offered IBM a bette

Read on Hacker News ↗ ← Back to News

Comments

No comments yet. Start the discussion.