Chapter 2.1: 8086 Architecture
Introduction
Learning Outcomes
Explain the 8086's data and address bus widths, how much memory it can address, and its place in the x86 family.
Describe the roles of the BIU and EU, the prefetch queue and the idea of pipelining.
Group the 14 registers; explain the roles of the segment registers and IP.
Compute a 20-bit physical address as segment × 10h + offset, by hand and step by step.
Overview
The 8086 at a Glance
- A 16-bit microprocessor introduced by Intel in 1978; the first member of the x86 family.
- Its registers, ALU and data bus are 16 bits; it processes 16 bits of data at a time.
- 20-bit address bus → 220 = 1,048,576 bytes = 1 MB of memory.
- 16-bit data bus: moves 2 bytes at a time between the processor, memory and I/O devices.
- CISC (complex instruction set) architecture: variable-length (1–6 byte) instructions, instructions that operate on memory.
- Its instruction set, the basis of the PC, survives through backward compatibility.
Unlike its sibling the 8088, which has an 8-bit external data bus, the 8086 is 16 bits throughout.
Overview
The 8086 in the x86 Family
| Processor | Year | Internal / external data bus | Address bus | Memory | Note |
|---|---|---|---|---|---|
| 8086 | 1978 | 16 / 16 bits | 20 bits | 1 MB | 6-byte prefetch queue |
| 8088 | 1979 | 16 / 8 bits | 20 bits | 1 MB | 4-byte queue; IBM PC (1981) |
| 80186 | 1982 | 16 / 16 bits | 20 bits | 1 MB | integrated peripherals |
| 80286 | 1982 | 16 / 16 bits | 24 bits | 16 MB | protected mode |
| 80386 | 1985 | 32 / 32 bits | 32 bits | 4 GB | 32-bit x86 (IA-32) |
Overview
Why a 20-Bit Address?
00000h, the highest FFFFFh.Overview
Memory Organization: The CPU Is Not Alone
- Puts all the functions of a CPU on a single integrated circuit.
- It has no RAM or ROM inside; only registers.
- Intermediate and final results are kept in registers.
- Reaches memory and I/O over the system bus.
- Needs external memory, a clock generator and buffer/latch circuits to run.
- CPU + program memory (ROM/Flash) + RAM + timers + I/O ports on one chip.
- Can work as a stand-alone system.
- Embedded uses: washing machines, remote controls, sensor nodes.
- Less computing power, lower cost and power consumption.
Overview
System Buses
| Bus | What does it carry? | On the 8086 |
|---|---|---|
| Address | the memory location or I/O port number to read or write | 20 bits → 1 MB of memory; 16 bits for I/O → 64 K ports |
| Data | instruction and data bytes between the processor and memory/I/O | 16 bits, one word (2 bytes) at a time |
| Control | read, write, interrupt requests, status information | RD', WR', M/IO', ALE, INTR, READY … |
Overview · Step through the code
Code Trace: Memory and I/O over the Buses
org 100h mov ax, 1000h mov ds, ax mov bx, 0200h mov al, [bx] ; memory read out 50h, al ; I/O write in al, 51h ; I/O read mov [bx+1], al ; memory write ret
Data segment DS = 1000h (base 10000h). Memory holds 5Ah at 10200h and I/O port 51h holds 3Ch (sample values).
BX = 0200h. Instruction fetch only; no bus cycle for data.
Memory read: the address bus carries the 20-bit 10200h, M/IO' = 1, RD' = 0. Memory puts 5Ah on the data bus → AL = 5Ah.
I/O write: the address bus carries only the port number (0050h, 16 bits), M/IO' = 0, WR' = 0; AL = 5Ah is on the data bus. Memory ignores this cycle.
I/O read: port 0051h, M/IO' = 0, RD' = 0. The device puts 3Ch on the data bus → AL = 3Ch.
Memory write: EA = BX + 1 = 0201h → PA = 10201h, M/IO' = 1, WR' = 0, data 3Ch. Memory and I/O share the same address and data buses; M/IO' tells them apart.
Internal Structure
Two Main Units: BIU and EU
- Handles all communication with the outside world: fetches instructions from memory.
- Reads operands from memory and writes results to memory or I/O.
- Forms the 20-bit physical address from the segment registers and IP.
- Fills the 6-byte prefetch queue.
- Takes the next instruction byte from the queue, decodes it and executes it.
- Performs arithmetic and logic operations in the ALU.
- Updates the general-purpose registers and flags.
- Asks the BIU when it needs an operand in memory; it is not connected to the external buses.
Internal Structure
8086 Block Diagram
Internal Structure
How the 8086 Works
The big picture. Let us follow one instruction step by step: ADD AX, BX.
1. The BIU computes the physical address of the instruction to fetch: CS × 10h + IP (address adder).
2. The 20-bit address goes onto the external address bus; the bus control logic starts a memory read cycle.
3. The incoming instruction bytes enter the 6-byte FIFO queue; IP advances by the number of bytes fetched.
4. When its turn comes, the EU takes the opcode over the Q bus; the control system decodes the instruction.
5. Control signals move AX and BX over the ALU data bus into the temporary registers, then into the ALU; the add takes place.
6. The result is written to AX and the flags (CF, ZF, SF, OF, PF, AF) are updated. Meanwhile the BIU keeps fetching the next bytes.
Internal Structure
Bus Interface Unit (BIU)
- Interfaces with external memory and I/O devices over the system bus.
- Forms the 20-bit physical address from a segment register and an offset (address adder).
- Fetches instructions from memory and writes them to the queue.
- Reads operands the EU requests from memory/I/O and writes results.
- Manages the 6-byte prefetch queue → makes pipelining possible.
- Segment registers:
CS,DS,SS,ES - Instruction pointer:
IP - Address adder (Σ)
- 6-byte instruction queue
- Bus control logic
Internal Structure
The Prefetch Queue
- A 6-byte FIFO (first in, first out) queue: bytes are used in the order fetched.
- While the EU executes, the BIU prefetches the next instruction bytes → pipelining.
- Once 2 bytes are free in the queue, the BIU fetches the next word.
- A branch (JMP, CALL, RET, conditional jump, interrupt) flushes the queue; the prefetched bytes are on the wrong path.
- 8086 instructions are 1–6 bytes (without prefixes); the queue holds the longest in full.
Internal Structure
Pipelining
F = fetch (BIU), E = decode + execute (EU). Each box is assumed to take 2 time units.
Without a pipeline: fetch (F) first, then execute (E); the BIU and EU take turns sitting idle.
8086: while the EU executes E1, the BIU fetches F2. Both units work at once; throughput roughly doubles.
Branching: if E3 is a JMP, the prefetched F4 and F5 are invalid. The queue is emptied and refilled from the target address.
Internal Structure
The Queue Step by Step
Start (or after a branch): the queue is empty, the EU waits. CS:IP = CS:0100h.
The BIU fetches word by word (B8 34, 12 01, D8 41); the queue fills. The EU starts decoding as soon as the first byte arrives.
The EU took the 3-byte MOV AX,1234h from the queue. The queue has 3 free slots (≥ 2).
While the EU executes, the BIU fetches the next word (EB 05). No waiting.
The EU took 01 D8 (ADD AX,BX); the BIU fetched 90 90.
The EU took 41 (INC CX); the BIU fetched two more NOP bytes, and the queue is full.
The EU executes EB 05: IP = 0108h + 5 = 010Dh. The 90s in the queue are invalid → the queue is flushed.
The BIU starts fetching again at 010Dh (an odd address, so 1 byte first). The EU waits for the byte.
Internal Structure
Prefetch and Decode Functions
- Fetches instructions from memory and keeps them in a buffer (the queue).
- A program counter holds the address of the next byte to fetch (on the 8086, IP and a counter inside the BIU do this).
- The EU takes instructions from the buffer instead of memory → memory access time is hidden.
- More instructions execute per unit of time.
- Turns machine code into control signals/micro-operations.
- Runs in parallel with prefetching.
- Decodes complex instructions such as conditional jumps, CALL and RET.
- Steers register-to-register and memory-to-register transfers.
Internal Structure
Execution Unit (EU)
Main parts of the EU:
- General-purpose registers
- Arithmetic logic unit (ALU)
- Special-purpose registers (SP, BP, SI, DI)
- Instruction register and decoder
- FLAGS (status) register
- Control system
Internal Structure
Arithmetic Logic Unit (ALU)
- Performs 8- and 16-bit arithmetic and logic operations.
- Arithmetic: add, subtract, multiply, divide, increment/decrement, compare.
- Logic: AND, OR, XOR, NOT, shifts and rotates.
- Updates the flags according to each result.
| Instruction | Operation | Size |
|---|---|---|
ADD AX, BX | AX ← AX + BX | 16 bits |
SUB AL, 5 | AL ← AL − 5 | 8 bits |
MUL BL | AX ← AL × BL | 8 → 16 |
DIV CX | AX ← DX:AX ÷ CX, DX ← remainder | 32 → 16 |
AND AL, 0Fh | clears the upper 4 bits of AL | 8 bits |
XOR AX, AX | AX ← 0 (ZF = 1) | 16 bits |
Internal Structure · Step through the code
Code Trace: What Does the ALU Do?
org 100h mov ax, 0010h mov bx, 0030h add ax, bx ; AX ← AX + BX sub al, 5 ; AL ← AL − 5 mov bl, 4 mul bl ; AX ← AL × BL mov dx, 0 mov cx, 3 div cx ; AX ← DX:AX ÷ CX and al, 0Fh ; clear upper 4 bits xor ax, ax ; AX ← 0 ret
The operands are loaded into registers: AX = 0010h, BX = 0030h. MOV does not use the ALU; the flags do not change.
add ax, bx: the ALU does a 16-bit add → AX = 0040h. No carry (CF = 0), result not zero (ZF = 0).
sub al, 5: an 8-bit subtract; only AL changes → AL = 3Bh (AX = 003Bh). No borrow: CF = 0.
BL = 4. mul bl: the product of 8-bit operands is 16 bits: 3Bh × 04h = 00ECh → AX. AH = 0, so CF = OF = 0; SF and ZF are undefined (?).
Setting up the divide: the dividend is the 32-bit DX:AX pair, so DX = 0; the divisor is CX = 3.
div cx: 236 ÷ 3 = 78 remainder 2 → quotient AX = 004Eh, remainder DX = 0002h. Flags are undefined after DIV.
and al, 0Fh: 0100 1110 AND 0000 1111 = 0000 1110 → AL = 0Eh. The upper 4 bits are cleared; AND sets CF = OF = 0.
xor ax, ax: any bit XORed with itself is 0 → AX = 0000h, ZF = 1. A shorter (2-byte) way to clear than mov ax, 0.
Internal Structure
Instruction Register, Decoder and Control
The EU takes the next instruction from the queue; its opcode is held here while it is decoded. Programs cannot access this register.
Decodes the opcode: which operation, which operands, which addressing mode? Passes that information to the control circuitry.
Directs the flow of instructions and data inside the processor; sequences the fetch–decode–execute cycle and coordinates the other parts.
The 8086 has no power management; those features came much later (e.g. the 386SL). The 8086's control unit is microcoded.
Internal Structure
Instruction Lengths
8086 instructions have variable length: opcode + (optional) addressing byte + displacement + immediate data.
| Instruction | Machine code (hex) | Bytes | Description |
|---|---|---|---|
INC CX | 41 | 1 | opcode only |
MOV AX, BX | 8B C3 | 2 | opcode + ModR/M byte |
ADD AL, 7Ch | 04 7C | 2 | short AL form + 8-bit immediate |
MOV BX, 4050h | BB 50 40 | 3 | opcode + 16-bit immediate (little-endian) |
MOV WORD PTR [BX+1234h], 5678h | C7 87 34 12 78 56 | 6 | ModR/M + 16-bit displacement + 16-bit immediate |
4050h → 50 first, then 40.A register-to-register MOV is 2 bytes (8B C3 or the equivalent 89 D8).
Internal Structure · Step through the code
Code Trace: Bytes and IP
org 100h inc cx mov bx, 4050h mov ax, bx add al, 7Ch mov word ptr [bx+1234h], 5678h ret
The program starts at 0100h. inc cx is just an opcode: 41 (1 byte) → IP = 0101h. CX = 1.
BB 50 40: BB = “16-bit constant into BX”; the constant is little-endian (50 first, then 40). 3 bytes → IP = 0104h.
8B C3: 8B = MOV r16, r/m16; ModR/M C3 = 11 000 011 → mod 11 (register), reg AX, r/m BX. 2 bytes → IP = 0106h.
04 7C: the short AL form + an 8-bit constant. AL = 50h + 7Ch = CCh, AX = 40CCh. IP = 0108h.
6 bytes: C7 + ModR/M 87 (mod 10: 16-bit displacement, r/m BX) + 34 12 + 78 56. EA = 4050h + 1234h = 5284h; 5678h is written there. IP = 010Eh.
C3 = RET (1 byte); IP gets 0000h from the stack (the COM program returns to DOS). Six instructions took 15 bytes: lengths range from 1 to 6 bytes.
Registers
The Register Set
- General-purpose: hold data and take part in arithmetic/logic; each splits into two 8-bit halves.
- Segment registers: point to the bases of the four active segments in memory. Special: IP points to the next instruction, FLAGS reflects the last result.
Registers
Internal Registers and Word Size
- The 8086 is a 16-bit integer (scalar, non-vector) processor; floating point needs a separate coprocessor (the 8087).
- It comes in a 40-pin dual in-line package (DIP).
- The size of the on-chip registers sets how much data the processor handles at once (the word size) → 16 bits.
- It gives the programmer 14 registers of 16 bits.
- Registers are the fastest storage in the processor: a memory access needs a bus cycle (≥ 4 clocks), a register access does not.
Registers
Segment Registers
- Segments live in memory; segment registers live inside the processor.
- Each segment register holds a segment's start address / 16 (segment base = register × 10h).
| CS Code Segment | Program code; CS:IP is the next instruction |
| DS Data Segment | Variables and data |
| SS Stack Segment | The stack; SS:SP, SS:BP |
| ES Extra Segment | Extra data; string destination ES:DI |
- A segment register cannot be loaded with an immediate:
MOV DS, 2000his invalid; useMOV AX, 2000h, thenMOV DS, AX. CScannot be changed with MOV; JMP FAR, CALL FAR, RET FAR, INT and IRET change it.- There is no direct segment-to-segment MOV (
MOV ES, DSis invalid).
Registers
Instruction Pointer (IP)
- A 16-bit register.
- Holds the offset of the next instruction in the code segment.
- Advances by each instruction's length as its bytes are fetched.
- Branch instructions (JMP, Jcc, CALL, RET, LOOP, INT) load IP with a new value.
- Programs cannot read or write IP directly (there is no
MOV IP, …). - Physical address of the next instruction: CS × 10h + IP.
CS = 4321h, IP = 1000h
43210h ; CS × 10h + 01000h ; IP -------- 44210h
The next instruction is at physical address 44210h.
Segmented Memory
Segmented Memory Architecture
- The 8086 addresses memory in segments.
- Every memory address is given as two 16-bit parts: segment : offset, e.g.
2000h:0010h. - The segment register points to the start of the segment.
- The offset is the distance of the byte from the start of the segment (0000h–FFFFh).
- The address adder in the BIU combines the two into a 20-bit physical address.
Logical address: the segment:offset pair the program uses.
Physical address: the actual 20-bit address placed on the address bus.
PA = segment × 10h + offset
Segmented Memory
Segment and Offset
Memory is 1 MB: 00000h–FFFFFh. We will build a 20-bit address from a segment register and an offset.
The segment register holds 1000h (16 bits).
The segment value is shifted left 4 bits (× 10h): 1000h → 10000h. A segment base is always a multiple of 16 (a paragraph boundary).
The offset is F000h. The largest offset is FFFFh, so the segment spans 10000h–1FFFFh (64 KB).
The adder: 10000h + F000h = 1F000h. This 20-bit value goes onto the address bus.
Segmented Memory
Step by Step: CS:IP → Physical Address
CS = 4321h (4 hex digits = 16 bits).
× 10h = append a 0 on the right in hex (shift left 4 bits): 43210h.
IP = 1000h is written below, right-aligned (the leftmost digit is blank = 0).
Add the digits from the right: 0+0, 1+0, 2+0, 3+1, 4+0 → 44210h. No carry.
CS = F000h, IP = FFF0h: the address of the first instruction in the BIOS after reset (the 8086 loads CS = FFFFh, IP = 0000h on reset; both give the same byte).
F000h × 10h = F0000h.
IP = FFF0h is right-aligned.
F0000h + FFF0h = FFFF0h: the last 16 bytes of the 1 MB. After reset the processor takes its first instruction from here (the same address as FFFFh:0000h).
Segmented Memory
Demo: Physical Address Calculator
The map shows the segment base and the 64 KB segment range. If the sum passes 1 MB, the 8086 truncates the address to 20 bits (wraparound).
Segmented Memory
Memory Segmentation
- The 20-bit address bus reaches 1 MB; a segment is at most 64 KB (16-bit offset).
- Only 4 segments are active at any time (CS, DS, SS, ES) → at most 256 KB is directly reachable at once. To reach another area, change a segment register.
- Segments are not 16 fixed pieces: one can start at any paragraph (16-byte) boundary, and segments may overlap or be disjoint.
1 MB / 64 KB = 16 is only arithmetic; 8086 segment starts are not fixed (65,536 possible starts).
Segmented Memory
Why Segmentation?
Pros
- 16-bit registers can address 20 bits (1 MB) of memory.
- Code, data and stack are kept apart; the program layout is clear.
- Relocatability: a program can be loaded elsewhere in memory just by changing the segment registers.
- Instructions stay short: most addresses are written as 16-bit offsets.
Cons
- A single array or structure cannot exceed 64 KB (otherwise you must switch segments).
- One physical address has many
segment:offsetforms → comparing pointers gets harder. - There is no protection between segments: a bad write can corrupt another segment.
- Address arithmetic burdens the programmer.
Segmented Memory
Same Address, Different Segment:Offset
| Logical address | Calculation | Physical address |
|---|---|---|
1234h:0005h | 12340h + 0005h | 12345h |
1000h:2345h | 10000h + 2345h | 12345h |
1200h:0345h | 12000h + 0345h | 12345h |
0234h:FFF5h | 02340h + FFF5h | 12335h (not 12345h) |
FFFFh:0010h | FFFF0h + 0010h = 100000h | 00000h (wraps to 20 bits on the 8086) |
1234h:0005h. A physical address has at most 4096 different forms.Segmented Memory · Step through the code
Code Trace: The Address Wraps Around at 1 MB
org 100h
mov ax, 0
mov ds, ax
mov byte ptr [0500h], 77h
mov ax, 0FFFFh
mov ds, ax
mov bl, [0510h] ; FFFF:0510
ret
DS = 0000h: the segment is at the very start of memory. A segment register cannot take a constant, so the value goes through AX.
mov byte ptr [0500h], 77h: 0000:0500 → 77h is written to physical 00500h.
DS = FFFFh: the segment starts at FFFF0h, the last 16 bytes of the 1 MB.
mov bl, [0510h]: the sum needs 21 bits; the 8086's 20 address lines carry only 00500h. The same byte is read: BL = 77h.
RET. Addresses from FFFF:0010 to FFFF:FFFF fall into 00000h–0FFEFh at the start of memory.
On the 80286 and later, if the 21st address line (A20) is enabled, FFFF:0510 really reaches 100500h; it can be disabled because some old 8086 programs rely on the wraparound.
Segmented Memory
Default Segments
| Access type | Segment | Offset source | Can it be overridden? |
|---|---|---|---|
| Instruction fetch | CS | IP | no |
| Stack operations (PUSH, POP, CALL, RET) | SS | SP | no |
BP addressing [BP+…] | SS | effective address | yes: DS:[BP] |
General data [BX], [SI], [DI], [1234h] | DS | effective address | yes: ES:[BX] |
| String source (MOVSB, LODSB) | DS | SI | yes |
| String destination (MOVSB, STOSB) | ES | DI | no |
MOV AL, ES:[BX] → physical address = ES × 10h + BX. The prefix adds 1 byte (26h) to the instruction.Segmented Memory · Step through the code
Code Trace: One Offset, Three Segments
org 100h mov ax, 2000h mov ds, ax mov ax, 3000h mov es, ax mov bx, 0010h mov bp, 0010h mov byte ptr [bx], 11h ; DS mov byte ptr [bp], 22h ; SS mov byte ptr es:[bx], 33h ; ES mov al, [bx] ; DS mov ah, [bp] ; SS ret
A segment register cannot take a constant; DS = 2000h goes through AX. In a COM program SS = CS (0700h here).
Likewise ES = 3000h. Now there are three segment bases: 07000h (SS), 20000h (DS), 30000h (ES).
BX and BP hold the same offset: 0010h. The segment used, not the offset, decides which byte is accessed.
[bx] uses DS by default: 2000h × 10h + 0010h = 20010h ← 11h.
[bp] uses SS by default: 0700h × 10h + 0010h = 07010h ← 22h. Same offset, different byte.
The es: prefix selects ES instead of DS (+1 byte, 26h): 30000h + 0010h = 30010h ← 33h.
mov al, [bx] reads DS:0010h again → AL = 11h (not the 33h at ES:0010h).
mov ah, [bp] reads SS:0010h → AH = 22h. Result AX = 2211h: three accesses, one offset, three physical addresses.
Segmented Memory · Step through the code
Code Trace: Access by Segment:Offset
AX ← 2000h. A segment register cannot take an immediate, so the value goes into AX first.
DS ← AX = 2000h. The data segment is now 20000h–2FFFFh.
BX ← 0010h (offset).
PA = 2000h×10h + 0010h = 20010h. 41h ('A') is written there.
AX ← 2001h.
DS ← 2001h: the segment base moved 16 bytes (one paragraph) → 20010h–3000Fh.
BX ← 0000h.
PA = 20010h + 0000h = 20010h → AL = 41h. 2000h:0010h and 2001h:0000h are the same byte!
SI ← FFFFh: the largest offset.
PA = 20010h + FFFFh = 3000Fh: the last byte of this segment. AH gets the value in that byte.
mov ax, 2000h mov ds, ax ; DS = 2000h mov bx, 0010h mov byte ptr [bx], 41h mov ax, 2001h mov ds, ax ; +16 bytes mov bx, 0000h mov al, [bx] ; same byte mov si, 0FFFFh mov ah, [si] ; last byte
Summary
Summary
16-bit data bus and registers, 20-bit address bus → 1 MB. CISC, variable-length instructions.
The BIU fetches and forms addresses; the EU decodes and executes. A 6-byte FIFO queue lets them work in parallel.
AX, BX, CX, DX · SP, BP, SI, DI · CS, DS, SS, ES · IP, FLAGS.
CS, DS, SS and ES point to the bases of the four active segments; a segment register cannot take an immediate.
PA = segment × 10h + offset. A segment is ≤ 64 KB, starts on a paragraph boundary, and segments may overlap.
Load IP with a new value and flush the prefetch queue.
Summary
Exercises
- If CS =
2F00hand IP =01A4h, what is the physical address of the next instruction? - Write the physical address
3A2C5hin normalizedsegment:offsetform; with DS =3000h, what must the offset be? - Why does
MOV DS, 1000hnot assemble? Give the correct form. - If the EU executes a
JMPwhile the queue holds 6 bytes, what happens to the queue? Why? - Can the 8086 execute one instruction while fetching another? Thanks to which units?
Hints / answers
- 2F000h + 01A4h = 2F1A4h.
3A2Ch:0005h; with DS = 3000h the offset = 3A2C5h − 30000h = A2C5h.- A segment register cannot take an immediate:
MOV AX, 1000h+MOV DS, AX. - The queue is flushed; the prefetched bytes came from the following addresses, not from the jump target.
- Yes: the BIU fetches while the EU executes (pipelining).
Summary
References
- Intel, 8086 16-Bit HMOS Microprocessor data sheet (231455).
- Intel, The 8086 Family User's Manual, 1979.
- B. B. Brey, The Intel Microprocessors, 8th ed., Pearson, 2009.
- M. A. Mazidi, J. G. Mazidi, D. Causey, The x86 PC: Assembly Language, Design, and Interfacing, 5th ed., Pearson, 2010.
- emu8086 documentation and instruction set reference.