Emulation Online
⭅ Previous (Intro to PC and DOS)

The brain of the PC: The 8088 CPU

The first piece of the DOS+PC platform we’ll look at in detail is the CPU. If you are new to computer architecture or retro-computing, you might want to read through our NES series, which is written for complete beginners.

The history of this chip is pretty interesting, and helps explain its somewhat confusing name.

Intel CPU History

Intel, creditted with making the first CPU, started with the 4004(1971). This was a 4 bit chip, meaning it operated on values of 4 bits at a time. Sufficient for the calculators they were intended for, but challenging to use for general purpose computing.

The followed up with a 4040 (1974), which was also 4 bit but used a newer process, meaning they could fit more transistors and thus logic in the same space. But this was still a 4 bit chip.

Later, they did an 8008, followed by the 8080. Both of these were 8 bit machines. This increased the size of numbers they could work on natively, without writing additional code for implementing long arithmetic manually. The small bus size both limited the size of a single value, but also limited the memory that the system could use:

Bus Width Value range (unsigned) Max Memory (Bytes)
4 0 ..= 31 32 bytes
8 0 ..= 255 256 bytes
12 0 ..= 4095 4096 bytes
14 0 ..= 8191 8192 bytes
16 0 ..= 65535 65K bytes
20 0 ..= 1048575 1M bytes

We can see that the amount of memory which can be used is identical to the maximum value that can be represented. In practice an 8 bit bus was too small even for 8 bit machines, so the 8008 had a 14 bit bus, and the 8080 had a 16 bit bus.

So more is better? In terms of capabilities, yes. However these larger chips increased both in cost of the chip, and the cost to assemble into a system. Larger chips lead to more costly system boards, often requiring additional layers and thus greatly increasing the cost of the board.

In order to make these improved capabilities available at lower cost, Intel later produced both an 8086 (16 bit), as well as an 8088 (16 bit, but 8 bit bus). This allowed the 16 bit system to function internally as a fast 16 bit calculator. But interacting with external memory would use only 8 data pins, allowing for simpler and cheaper boards and memories.

The first PC used this 8088. A 16 bit system, but limited to reading / writing 8 bits externally at a time. Besides the reduced external data bus, the 8088 and 8086 ran exactly the same code. For the rest of the article, we’ll talk about the software of the 8086, but know that this refers to code that could run on both systems.

CPU Model Year Internal Bits Data bus (external bits) Address bus => Max memory Transistors
4004 1971 4 4 12 => 4K 2300
4004 1974 4 4 12 => 4K 3000
8008 1972 8 8 14 => 8K 3500
8080 1974 8 8 16 => 65K 4500/6000
8086 1978 16 16 20 => 1M 29K
8088 1979 16 8 20 => 1M 29K

The 8086 / 8088 Instruction set

With the history out of the way, we can understand the significance of the chip. Another way we can appreciate it is by comparing with another popular CPU of the time, the MOS 6502. We covered this in detail as part of the NES series, so here is a link if you want to read more in detail: NES 6502 articles. The rest of the article wont assume 6502 expertise, but we’ll link to some relevant snippets throughout this article if you want to read more.

Lets start with a high level comparison, then we’ll look at one instruction in detail.

CPU Intel 8086 MOS 6502
clock frequency 4.77 MHz 1 - 3 MHz
clocks per instruction 2 - 16* 2 - 7
general registers ax/bx/cx/dx si/di a/x/y
bytes per opcode variable 1

Add on the 8086:

ADD = Add, ignore carry.

# opcodes description byte 1 byte 2 byte 3
4 Reg/Mem <-> Reg 000000dw mod reg r/m
4 Immediate to Reg/mem 100000sw mod 000 r/m data
2 Immediate to Acc 0000010w data data2 if w == 1

ADC = Add with carry.

# opcodes description byte 1 byte 2 byte 3
4 Reg/mem <-> Reg 000100dw mod reg r/m
4 Imm to Reg/Mem 100000sw mod 010 r/m data
2 Imm to Acc 0001010w data data if w = 1

8086 has two different add instructions, one acknowledges the carry bit, and the other ignores it. The letters in that first instruction/opcode byte represent variables, so can take on either bit value. So 000000dw represents 4 different values, with dw one of 00, 01, 10, 11.

The w bit is interesting. Since Intel has pushed for backwards compatibility in its instruction set, it aims to also support software written for earlier 8 bit chips. To make this work, 16 bit registers that had a counterpart in earlier chips (ax/bx/cx/dx) can also be used as 2 separate 8 bit registers. W means width or wide, and when set to 1 indicates the operand is a 16 bit register.

AX is a 16 bit register, but many instructions can operate on an 8 bit half. AL is the lower 8 bits of AX, and AH is the upper 8 bits of AX.

We see here that the 8086 has two different instructions to add numbers (or more if you could the LEA instructions), and 20 ways to configure these instructions. Now lets look at the 6502.

Add on the 6502

ADC = Add Memory to Accumulator with Carry

addressing assembler
immediate ADC #oper
zeropage ADC oper
zeropage,X ADC oper,X
absolute ADC oper
absolute,X ADC oper,X
absolute,Y ADC oper,Y
(indirect,X) ADC (oper,X)
(indirect),Y ADC (oper),Y

Source: Masswerk 6502 Reference

Here, 6502 uses a single instruction to add numbers. If you want to ignore the carry, you are responsible for clearing the carry bit before adding. The instruction has 7 variations or addressing modes. All instructions encode their arguments in essentially the same way. Not all instructions support all modes, but there are at most 10 modes that can be supported by an instruction.

We can see that the 8086 had a more complex instruction set. Whether that is good or bad is largely a matter of taste. I can say that during my time writing test roms for the NES, I largely had the 6502 instuction set memorized. While I havent written nearly as much assembly for the 8086 (yet), I suspect I’ll be relying on a reference.

Next up: unique 8086 features

That wraps up our quick tour of hte 8086. In the next article we’ll look at a few unique features of the 8086, such as IO ports and memory segmentation. If you enjoyed this article, make sure to subscribe to the email list to be notified when the next article is available.

⭅ Previous (Intro to PC and DOS)

We publish about 1 post a week discussing emulation and retro systems. Join our email list to get notified when a new post is available. You can unsubscribe at any time.