(a) CS = 1000H and IP = E000H. Find the address of the next instruction. (b) For MOV CL, 04H[SI][BP] with SS = 1131H, DS = 2010H, BX = 0300H, BP = 1301H and SI = 0032H, find the physical address of the source operand.
The Intel 8086 (1978) is the 16-bit CISC chip that founded the x86 family: a BIU/EU split with a 6-byte prefetch queue, segmented 1 MB memory, 9 flags, 256 interrupt types and rich addressing modes, interfaced through the 8255, 8259, 8237/8257, 8253 and 8251.
A microprocessor is a complete CPU on one chip: it fetches instructions from memory, decodes them and executes them. Intel's 8086, released in 1978, is a 16-bit microprocessor — its ALU, registers and data bus all handle 16 bits at a time. It founded the x86 family (80186, 80286, 80386, Pentium, today's Core and Ryzen), so its register names and segment ideas still live inside every PC.
| Feature | 8086 |
|---|---|
| Introduced | 1978 by Intel; chief architect Stephen Morse |
| Technology and package | HMOS, about 29,000 transistors, 40-pin DIP, single +5 V supply |
| Clock | 5 MHz (8086), 8 MHz (8086-2), 10 MHz (8086-1); clock comes from the 8284A |
| Data bus | 16 bits, time-multiplexed with the low address lines as AD0–AD15 |
| Address bus | 20 bits → 2²⁰ = 1,048,576 bytes = 1 MB of memory |
| I/O space | 16-bit port addresses → 65,536 byte ports (or 32,768 word ports) |
| Instruction set | CISC: variable-length instructions of 1 to 6 bytes, many addressing modes |
| Interrupts | 256 types through a 1 KB interrupt vector table |
| Sibling | 8088 (1979): same 16-bit inside, 8-bit external data bus, 4-byte queue; used in the IBM PC (1981) |
Inside, the 8086 is split into two units that work at the same time. The Bus Interface Unit (BIU) handles every contact with the outside world: it forms 20-bit addresses, fetches instruction bytes, and reads or writes operands in memory and I/O. The Execution Unit (EU) decodes and executes instructions; it never drives the buses itself but asks the BIU for any operand it needs.
The prefetch queue. Whenever at least two of the six queue bytes are empty and the EU is not using the bus, the BIU fetches the next instruction bytes in advance. While the EU executes one instruction, the following ones are already waiting, so fetch and execute overlap. This two-stage pipelining is why the 8086 outruns an 8085 at the same clock rate.
A register is a storage cell inside the CPU, far faster than memory. The 8086 has fourteen 16-bit registers. The four general-purpose registers can also be used as eight 8-bit halves: AX = AH:AL, BX = BH:BL, CX = CH:CL and DX = DH:DL (H = high byte, L = low byte). Each register also has a special job that some instructions assume automatically.
| Register | Name | Special job |
|---|---|---|
| AX | Accumulator | Implicit operand of MUL, DIV, IN, OUT and the string LODS/STOS; fastest for arithmetic |
| BX | Base | The only general register usable as a memory pointer, e.g. [BX] |
| CX | Count | Counter for LOOP and REP; CL holds a multi-bit shift/rotate count |
| DX | Data | Port address in IN/OUT DX; high word of the 32-bit product or dividend in MUL/DIV |
| SP | Stack pointer | Offset of the top of stack within SS; PUSH subtracts 2, POP adds 2 |
| BP | Base pointer | Pointer to data on the stack (parameters, locals); defaults to SS |
| SI | Source index | Source offset for string instructions (DS:SI); array index |
| DI | Destination index | Destination offset for string instructions (ES:DI); array index |
| CS, DS, SS, ES | Segment registers | Start (paragraph number) of the code, data, stack and extra segments |
| IP | Instruction pointer | Offset of the next instruction byte to fetch, within CS |
| FLAGS | Flag register | Nine status and control bits, shown below |
A 16-bit register can hold only 2¹⁶ = 65,536 different values, enough for 64 KB. To reach 1 MB the 8086 combines two 16-bit numbers: a segment value that marks where a 64 KB window begins, and an offset — the effective address (EA) — that says how far into the window the byte lies. The BIU's address adder computes the 20-bit physical address for every bus cycle.
Every segment starts on a multiple of 16 (a paragraph boundary) and spans 64 KB: segment value 2000H covers 20000H–2FFFFH. Segments may be separate, adjacent or overlapping, so one physical byte has many names — 12345H is 1234H:0005H, 1000H:2345H and 1200H:0345H alike. Each instruction uses a default segment, which a segment-override prefix can sometimes change.
| Kind of access | Offset from | Default segment | Override allowed? |
|---|---|---|---|
| Instruction fetch | IP | CS | No |
| Stack operation (PUSH, POP, CALL, RET) | SP | SS | No |
| Memory operand whose EA uses BP | EA | SS | Yes, e.g. DS:[BP] |
| Any other memory operand (BX, SI, DI, direct) | EA | DS | Yes, e.g. ES:[BX] |
| String source | SI | DS | Yes |
| String destination | DI | ES | No |
Why segmentation? It lets 16-bit registers reach 1 MB; it keeps code, data and stack apart; and it makes programs relocatable — code written in offsets runs anywhere once the loader sets the segment registers. The price is the 64 KB limit per segment and the bookkeeping of segment registers, which later processors (80286, 80386) relaxed with protected mode.
Forty pins cannot carry 20 address lines, 16 data lines and all the control signals separately, so several pins do double duty. AD0–AD15 carry the address in the first clock of a bus cycle and data afterwards; A16/S3–A19/S6 carry the top address bits and then status. An external latch (8282 or 74LS373) captures the address when ALE (address latch enable) pulses, so memory sees a steady 20-bit address.
| Pin(s) | Purpose |
|---|---|
| AD0–AD15 | Multiplexed address/data bus |
| A16/S3–A19/S6 | High address bits, then status: S4 S3 = 00 ES, 01 SS, 10 CS (or none), 11 DS; S5 = IF; S6 = 0 |
| BHE̅/S7 | Bus high enable: 0 = transfer uses the upper data byte D8–D15 (odd bank) |
| RD̅ | Read strobe for memory or I/O |
| READY | Pulled low by slow memory or I/O to insert wait states; synchronised by the 8284A |
| INTR, NMI | Maskable, level-triggered interrupt input; non-maskable, edge-triggered interrupt input |
| TEST̅ | Tested by the WAIT instruction (used to synchronise with the 8087 coprocessor) |
| RESET | Clears flags and DS, SS, ES; sets CS = FFFFH, IP = 0000H, so execution starts at FFFF0H |
| CLK | Clock from the 8284A (one-third duty cycle) |
| MN/MX̅ (pin 33) | Tied to +5 V = minimum mode; tied to ground = maximum mode |
| BHE̅ | A0 | What is transferred |
|---|---|---|
| 0 | 0 | Whole 16-bit word on D0–D15 (word at an even address) |
| 0 | 1 | Upper byte from/to an odd address, on D8–D15 |
| 1 | 0 | Lower byte from/to an even address, on D0–D7 |
| 1 | 1 | Nothing (no transfer) |
A basic bus cycle takes four clock states. In T1 the address goes out and ALE latches it; in T2 RD̅ or WR̅ is asserted and the bus turns around for data; in T3 the data moves — READY is checked, and if it is low, wait states (Tw) are inserted after T3; T4 ends the cycle. At 5 MHz one cycle without waits takes 4 × 200 ns = 800 ns.
An interrupt makes the CPU pause the current program, run a special routine — the interrupt service routine (ISR) — and then resume exactly where it stopped. The 8086 supports 256 interrupt types (0–255), raised three ways: by hardware on the NMI and INTR pins, by software with INT n, and internally by error conditions such as divide overflow or single-stepping.
| Type | Name | Raised by |
|---|---|---|
| 0 | Divide error | DIV/IDIV with a zero divisor or a quotient too large |
| 1 | Single step | TF = 1 (after every instruction) |
| 2 | NMI | Rising edge on the NMI pin — power failure, memory parity error |
| 3 | Breakpoint | INT 3, a one-byte instruction (CCH) planted by debuggers |
| 4 | Overflow | INTO executed while OF = 1 |
| 5–31 | Reserved | Kept by Intel for later processors |
| 32–255 | Available | Software INT n and hardware devices (for example through an 8259) |
Priority (Intel's order): divide error, INT n and INTO (highest) → NMI → INTR → single step (lowest). Because one INTR pin must serve many devices, systems add the 8259A Programmable Interrupt Controller (PIC). It accepts 8 requests IR0–IR7 and latches them in the IRR (interrupt request register); the IMR (interrupt mask register) blocks masked lines; a priority resolver picks the winner, marks it in the ISR (in-service register) and raises INT to the CPU. On the second INTA̅ it supplies the type: the vector base programmed in ICW2 plus the IR number.
The 8259 is set up with ICW1–ICW4 (initialisation: edge or level trigger, single or cascade, vector base, 8086 mode, auto-EOI) and steered with OCW1–OCW3 (operation: masks, end-of-interrupt, priority rotation, reading IRR/ISR). Priority is fully nested by default (IR0 highest) or rotating, and every ISR must send an EOI (end of interrupt) before IRET. In cascade, each of the master's 8 inputs can take a slave 8259, giving 8 × 8 = 64 levels; lines CAS0–CAS2 tell the slaves which one is being acknowledged.
An addressing mode is the rule an instruction uses to locate its operand. For a memory operand the EU first computes the 16-bit effective address (EA) and the BIU then adds segment × 10H. On the 8086 only BX, BP, SI and DI (with an optional 8- or 16-bit displacement) can form an EA — [AX], [CX], [DX] and [SP] are illegal. Try every mode with your own register values in the 8086 address & modes tool on this page.
| Mode | Example | Where the operand is | Segment |
|---|---|---|---|
| Immediate | MOV AX, 1562H | The data 1562H is part of the instruction | — |
| Register | MOV AX, BX | In a register | — |
| Direct | MOV AX, [1562H] | Memory; EA = 1562H (displacement only) | DS |
| Register indirect | MOV AX, [BX] | Memory; EA = BX, SI or DI | DS |
| Based | MOV AX, [BX + 08H] | EA = BX or BP + displacement | DS (SS with BP) |
| Indexed | MOV AX, [SI + 20H] | EA = SI or DI + displacement | DS |
| Based indexed | MOV AX, [BX + SI] | EA = (BX or BP) + (SI or DI) | DS (SS with BP) |
| Based indexed with displacement | MOV AX, [BP + DI + 10H] | EA = base + index + displacement | SS with BP, else DS |
| String | MOVSB | Source DS:SI, destination ES:DI; SI, DI step by 1 or 2 as DF says | DS / ES |
| I/O port, direct | IN AL, 80H | 8-bit port number in the instruction (0–255) | I/O space |
| I/O port, indirect | OUT DX, AL | 16-bit port number in DX (0–65535) | I/O space |
| Relative | JNZ NEXT | Target = IP + signed displacement (−128 to +127 for short jumps) | CS |
| Implied | CLC, DAA | Operand implied by the opcode | — |
Quick worked case. Let DS = 3000H, SS = 5000H, BX = 0200H, BP = 0400H and SI = 0050H. MOV AL, [BX + SI + 05H] gives EA = 0200H + 0050H + 0005H = 0255H in DS, so PA = 30000H + 0255H = 30255H. Swap BX for BP — MOV AL, [BP + SI + 05H] — and EA = 0455H in SS, so PA = 50000H + 0455H = 50455H.
The 8086 instruction set falls into six groups. Knowing which group an instruction belongs to usually tells you whether it touches the flags — a favourite one-mark question.
| Group | Examples | Notes |
|---|---|---|
| Data transfer | MOV, PUSH, POP, XCHG, XLAT, IN, OUT, LEA, LDS, LES, LAHF, SAHF, PUSHF, POPF | Affect no flags (SAHF and POPF load them); LDS/LES load a 32-bit pointer into a register plus DS/ES |
| Arithmetic | ADD, ADC, SUB, SBB, INC, DEC, NEG, CMP, MUL, IMUL, DIV, IDIV, DAA, DAS, AAA, CBW, CWD | Update status flags; INC and DEC leave CF unchanged; MUL/DIV use AX (and DX) implicitly |
| Logical, shift, rotate | AND, OR, XOR, NOT, TEST, SHL/SAL, SHR, SAR, ROL, ROR, RCL, RCR | AND/OR/XOR/TEST clear CF and OF; NOT changes no flags; shift count is 1 or CL |
| String | MOVS, CMPS, SCAS, LODS, STOS with REP, REPE/REPZ, REPNE/REPNZ | DS:SI to ES:DI; CX counts repetitions; DF picks the direction |
| Program transfer | JMP, Jcc (JZ, JC, JG…), CALL, RET, LOOP, LOOPZ, JCXZ, INT, INTO, IRET | Conditional jumps are short (−128 to +127); far forms reload CS |
| Processor control | CLC, STC, CMC, CLD, STD, CLI, STI, HLT, NOP, WAIT, LOCK, ESC | Change individual flags or the processor state |
; Add the N bytes of ARRAY; 16-bit result in SUM (MASM syntax)
DATA SEGMENT
ARRAY DB 25H, 12H, 0F0H, 07H, 33H
N EQU 5
SUM DW ?
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA
START: MOV AX, DATA ; a segment register cannot take an
MOV DS, AX ; immediate, so go through AX
LEA SI, ARRAY ; SI -> first element (register indirect below)
MOV CX, N ; loop count
XOR AX, AX ; AX = 0, also clears CF
NEXT: ADD AL, [SI] ; add one byte
ADC AH, 00H ; carry from AL goes into AH
INC SI ; next element
LOOP NEXT ; CX = CX - 1, repeat while CX != 0
MOV SUM, AX ; SUM = 0161H for this data
MOV AH, 4CH ; return to DOS
INT 21H
CODE ENDS
END START; Copy 100 bytes from SRC (in DS) to DST (in ES)
CLD ; DF = 0: SI and DI auto-increment
LEA SI, SRC ; DS:SI = source
LEA DI, DST ; ES:DI = destination
MOV CX, 100 ; byte count
REP MOVSB ; repeat MOVSB until CX = 0| Data transfer scheme | How it works | 8086 hardware used |
|---|---|---|
| Programmed I/O — synchronous | The device is always ready (or its timing is known); the CPU simply executes IN/OUT | Direct IN/OUT to a latch or LED port |
| Programmed I/O — asynchronous (handshaking) | The CPU first checks a ready/busy status bit, or exchanges strobe/acknowledge signals, and transfers only when the device is ready | 8255 mode 1 handshake lines (STB̅, IBF, OBF̅, ACK̅) |
| Interrupt-driven I/O | The device interrupts when ready; the ISR does the transfer, so there is no busy-waiting | INTR/NMI pins, 8259 PIC |
| Direct memory access (DMA) | A DMA controller takes the buses and moves a whole block between device and memory | HOLD/HLDA pins, 8237 or 8257 DMA controller |
8255A PPI (programmable peripheral interface) provides 24 parallel I/O lines: port A (8), port B (8) and port C (8, usable as two 4-bit halves PC7–PC4 and PC3–PC0). Port A with upper C forms group A; port B with lower C forms group B. Address lines A1 A0 select port A (00), port B (01), port C (10) or the control register (11). Mode 0 is simple I/O, mode 1 is strobed I/O with handshaking (port C lines become STB̅, IBF, INTR or OBF̅, ACK̅, INTR), mode 2 is a bidirectional bus for port A only, and the BSR (bit set/reset) mode sets or clears any single port C bit. After reset every port is an input.
| Chip | Role | Key facts |
|---|---|---|
| 8259A | Programmable interrupt controller | 8 levels, cascade to 64; IRR, ISR, IMR, priority resolver; ICW1–ICW4, OCW1–OCW3 |
| 8237A | DMA controller | 4 channels, 16-bit address and count per channel; single, block, demand and cascade modes; memory-to-memory via channels 0 and 1; used in the IBM PC |
| 8257 | DMA controller (8085 family, also used with the 8086) | 4 channels; 16-bit address and 14-bit count per channel (top 2 count bits = read/write/verify); KPSC keys it as the programmable DMA controller |
| 8253 / 8254 | Programmable interval timer | 3 independent 16-bit down counters, each with CLK, GATE, OUT; binary or BCD; 6 modes; the 8254 adds read-back and faster clocks |
| 8251A | USART (serial) | Synchronous and asynchronous; 5–8 data bits, parity, 1/1½/2 stop bits; baud factor ×1, ×16, ×64; TxRDY, RxRDY status |
| 8279 | Keyboard/display controller | Scans up to 64 keys into an 8-byte FIFO; refreshes a 16-digit display |
| 8284A, 8288 | Clock generator, bus controller | CLK, READY and RESET synchronisation; maximum-mode control signals |
| 8253 mode | Name | Typical use |
|---|---|---|
| 0 | Interrupt on terminal count | OUT goes high when the count reaches 0 — timeouts, event counting |
| 1 | Hardware-retriggerable one-shot | A fixed-width low pulse started by a GATE edge |
| 2 | Rate generator (divide-by-N) | A one-clock pulse every N clocks — periodic ticks |
| 3 | Square-wave generator | OUT high for N/2 and low for N/2 clocks — baud-rate clocks, tones |
| 4 | Software-triggered strobe | One strobe pulse when the written count expires |
| 5 | Hardware-triggered strobe | One strobe pulse after a GATE edge (retriggerable) |
Try the problem first, then reveal the working one step at a time.
(a) CS = 1000H and IP = E000H. Find the address of the next instruction. (b) For MOV CL, 04H[SI][BP] with SS = 1131H, DS = 2010H, BX = 0300H, BP = 1301H and SI = 0032H, find the physical address of the source operand.
In 8-bit signed arithmetic the 8086 computes −62 + (−75) (MOV AL, −62 then ADD AL, −75). Find AL and the states of CF and OF, along with the other status flags.
A program executes INT 21H. Memory bytes 00084H, 00085H, 00086H and 00087H hold 00H, 10H, 00H and 20H. Where is the ISR, and what does the CPU push before going there? Where is the NMI vector stored?
An 8255 is mapped at ports 80H (port A), 81H (port B), 82H (port C) and 83H (control). Make port A an input, port B an output, port C upper an input and port C lower an output, all in mode 0. Then set bit PC5 in BSR mode. Give the control words and the 8086 instructions.
Given DS = 2000H, SS = 3000H, ES = 4000H, BX = 1000H, BP = 0F00H, SI = 0100H and DI = 0200H, find the EA and physical address for (a) MOV AX, [BX + DI + 10H]; (b) MOV [BP + 05H], CL; (c) the source and destination of one MOVSB with DF = 0, and SI and DI afterwards.
Predict AL and all six status flags after MOV AL, 96H followed by ADD AL, 6AH.
An 8253 at ports 40H–43H is clocked at 2 MHz. Program counter 0 to produce a 1 kHz square wave with binary counting. Give the count, the control word and the instruction sequence.
(a) At which addresses is the vector for type 13H stored? (b) Which type's vector begins at 00040H? (c) Which range of the IVT is free for user-defined interrupts?
Write the 8255 control word for: port A as a mode 1 input port, port B as a mode 0 output port, the free port C upper lines as outputs and port C lower as outputs. Which port C lines become port A's handshake signals, and which BSR word enables port A's interrupt (INTE A is controlled by PC4)?
12 questions. 70 % passes the topic quiz (+30 XP, +20 more for 100 %). Exam scoring: +1 correct, −⅓ wrong.
Modelled on real KPSC questions (reworded) with the same concept and answer; each links to its original paper.