Chapter 2.1: 8086 Architecture

Chapter 2.1: 8086 Architecture · Study Questions
Buses and memoryBIU and EUPipeliningPrefetch queueInstruction lengthIPSegment registersPhysical addressNormalizationAddress wraparoundDefault segment
Sercan KÜLCÜ · Giresun University · Computer Engineering

Multiple Choice · Overview

Question 1: The Buses of the 8086

Which statement is correct for the 8086?

A: The 8086's registers, ALU and data bus are 16 bits wide: it moves 2 bytes at a time. The 20-line address bus selects 220 = 1,048,576 bytes (1 MB). A 16-bit address and 64 KB belong to the 8080/8085, a 24-bit address and 16 MB to the 80286. The data bus and the address bus measure different things: one how much data at a time, the other how much memory.

Classic Question · Overview

Question 2: Address Spaces

Calculate for an 8086 system.

  1. What is the hexadecimal range of memory addresses? How many bytes is that?
  2. I/O addresses are 16 bits. At most how many ports can be addressed?
  3. At most how many bytes arrive over the data bus in one read bus cycle?
  4. Segment bases start on 16-byte paragraph boundaries. How many possible segment starting points are there in 1 MB?
Show answer
  1. 20 bits = 5 hexadecimal digits: 00000h – FFFFFh, 220 = 1,048,576 bytes.
  2. 216 = 65,536 ports (0000h – FFFFh). In an I/O access A19–A16 = 0.
  3. The data bus is 16 bits → 2 bytes (one word, a single cycle at an even address).
  4. 1,048,576 / 16 = 65,536: every value a 16-bit segment register can hold points to one paragraph.

Multiple Choice · Overview

Question 3: The System Bus

Which statement about the system bus of the 8086 is correct?

B: Only the CPU generates the address: the address bus is unidirectional and 20 lines address 2²⁰ = 1 MB. The data bus has 16 lines and is bidirectional (read and write). Read/write (RD, WR) and memory/I/O (M/IO) information is on the control bus.

Short Answer · Overview

Question 4: The Order of a Memory Read

MOV AL, [memory] is executed, the memory read takes the steps below; what is the correct order? What is different in a write cycle?
(1) Memory puts the requested byte on the data bus.
(2) The CPU puts the address on the address bus.
(3) The CPU writes the byte on the data bus into AL.
(4) RD becomes active on the control bus (M/IO = memory).

Show answer

Order: 2 → 4 → 1 → 3. First the address, then the “read” signal; memory puts the data out, the CPU takes it. On the 8086 this is one bus cycle (T1–T4, 4 clock periods).

In a write cycle, in step 1 the CPU puts the data on the data bus and the WR signal becomes active; memory stores the byte.

The instruction itself is fetched the same way: the CPU reads the bytes at CS:IP and advances IP by the instruction length (fetch – decode – execute).

Multiple Choice · Internal Structure

Question 5: The Job of the BIU

What is the job of the bus interface unit (BIU) in the 8086?

C: The BIU is the unit that talks to the outside world: it computes the 20-bit address as segment × 10h + offset, fills the 6-byte prefetch queue and runs the bus cycles. The segment registers and IP are in the BIU. Decoding and executing instructions and updating the flags is the EU's job, and interrupt prioritization belongs to an interrupt controller such as the 8259A.

Multiple Choice · Internal Structure

Question 6: Inside the EU

Which of the following is located inside the execution unit (EU)?

B: The EU contains the general-purpose registers, the pointer/index registers, the ALU, the flags register and the control system. The segment registers, IP, address adder and prefetch queue are in the BIU. The EU is not connected directly to the external buses; if an operand in memory is needed, it asks the BIU.

Classic Question · Internal Structure

Question 7: When Fetch and Execute Overlap

Fetching each instruction (F, BIU) takes 2 time units, and decoding and executing it (E, EU) takes 2 time units. For 5 instructions:

  1. If the BIU and EU worked one after the other (no pipelining), what would the total time be?
  2. If, as in the 8086, the BIU fetches the next instruction while the EU executes, what is the time?
  3. If the 3rd instruction is a JMP and the queue is flushed, what is the time?
Show answer
  1. 5 × (2 + 2) = 20 units.
  2. The first fetch takes 2 units, then one instruction finishes every 2 units: 2 + 5 × 2 = 12 units.
  3. The 4th instruction prefetched during E3 is on the wrong path. The target is fetched only when E3 ends (unit 8): F4 8–10, E4 10–12, E5 12–14 → 14 units. Branching takes back part of the gain.

Step-by-Step Trace · Internal Structure

Question 8: Tracing the Queue

The program starts at 0100h. The BIU fetches a word whenever at least 2 bytes of room open up in the queue. While the JMP executes, which bytes are in the queue and what happens to them? What are AL and BL at the end?

Queue (6 bytes) →BIU next:0100hEU: waiting (queue empty)AL00hBL00h

At first the queue is empty; the EU waits for the first byte. The BIU starts fetching word by word from 0100h.

Queue (6 bytes) →B30702C3EB02BIU next:0108hEU: MOV AL, 5 (B0 05)AL05hBL00h

The BIU filled the queue with three words. The EU took B0 05 (AL = 05h); when 2 bytes freed up, the BIU fetched EB 02.

Queue (6 bytes) →02C3EB029090BIU next:010AhEU: MOV BL, 7 (B3 07)AL05hBL07h

The EU took B3 07 (BL = 07h); the BIU fetched 90 90. The EU never had to wait.

Queue (6 bytes) →EB029090F490BIU next:010ChEU: ADD AL, BL (02 C3)AL0ChBL07h

AL = 05h + 07h = 0Ch. The BIU also fetched F4 90 at 010Ah; the queue is full again.

Queue (6 bytes) →9090F490BIU next:010AhEU: JMP SHORT (EB 02)AL0ChBL07hqueue flushed

JMP: IP = 0108h + 2 = 010Ah. The 4 bytes in the queue (90 90 F4 90) came from sequential addresses, so they are invalid and are discarded.

Queue (6 bytes) →90BIU next:010ChEU: HLT (F4)AL0ChBL07h

The BIU fetches again from 010Ah (F4 90); the EU waited meanwhile. F4 = HLT. Result: AL = 0Ch, BL = 07h.

org 100h
mov al, 5        ; B0 05
mov bl, 7        ; B3 07
add al, bl       ; 02 C3
jmp short done   ; EB 02
nop              ; 90
nop              ; 90
done: hlt        ; F4
nop              ; 90

Multiple Choice · Internal Structure

Question 9: A Three-Byte Instruction

8086 instructions have variable length. Which of the following takes up 3 bytes of memory?

D: MOV BX, 4050h = BB 50 40: opcode + 16-bit immediate value (little-endian). INC CX = 41 (1 byte), MOV AX, BX = 8B C3 (opcode + ModR/M, 2 bytes), and the last instruction is C7 87 34 12 78 56: ModR/M, a 16-bit displacement and a 16-bit immediate value make it 6 bytes.

Multiple Choice · Registers

Question 10: The Instruction Pointer

Which statement about the instruction pointer (IP) is correct?

A: IP is a 16-bit offset; the physical address is generated in the BIU as CS × 10h + IP. MOV IP, … does not exist as an instruction: only JMP, Jcc, CALL, RET, LOOP, INT and IRET change IP. SP points to the top of the stack; the opcode is held in the instruction register, which is invisible to the programmer.

Spot the Bug · Registers

Question 11: Instructions That Do Not Assemble

Each of the following lines gives an error in an 8086 assembler. Explain why and give correct code that does the same job.

MOV DS, 1000h
MOV ES, DS
MOV CS, AX
MOV IP, 0100h
MOV AL, BX
Show answer
WrongReasonCorrect
MOV DS, 1000han immediate value cannot be loaded into a segment registerMOV AX, 1000h
MOV DS, AX
MOV ES, DSno MOV from segment register to segment registerPUSH DS
POP ES
MOV CS, AXCS cannot be changed with MOVfar JMP/CALL, RETF, INT, IRET
MOV IP, 0100hIP is not accessible to the programmerto jump to the label at 0100h, use JMP
MOV AL, BX8 bit ← 16 bit mismatchMOV AL, BL

Classic Question · Segmented Memory

Question 12: Computing a Physical Address

Find the 20-bit physical addresses on the 8086 of the following segment:offset pairs.

  1. CS = 1A2Bh, IP = 0C30h
  2. DS = 7000h, BX = FFF0h
  3. B800h:0FA0h (text-screen memory)
  4. FF00h:1200h
Show answer
segment × 10h+ offsetPA
11A2B0h0C30h1AEE0h
270000hFFF0h7FFF0h
3B8000h0FA0hB8FA0h
4FF000h1200h100200h → 00200h

The last sum exceeds 1 MB; since the 8086 has no A20 line, the top bit is dropped and the address wraps around to 00200h. In example 2 the result is close to the segment's limit: segment 7000h covers the range 70000h–7FFFFh.

Step-by-Step Trace · Segmented Memory

Question 13: Tracing Segment:Offset

What is the physical address of each memory access? What is AL when the program finishes, and to which physical addresses was the value 5Ah written?

DS3000hoffset—PA—byte—data segment: 30000h – 3FFFFh

Because a constant cannot be loaded into a segment register, it goes into AX first and then into DS: DS = 3000h. The data segment starts at 30000h.

DS3000hoffset0020hPA30020hbyte5AhPA = DS × 10h + offset = 30000h + 0020hdata segment: 30000h – 3FFFFh

PA = 30000h + 0020h = 30020h; 5Ah is written there.

DS3002hoffset—PA—byte—data segment: 30020h – 4001Fh

DS = 3002h: the segment base moved forward by 2 paragraphs (32 bytes = 20h) → 30020h.

DS3002hoffset0000hPA30020hbyte5AhPA = DS × 10h + offset = 30020h + 0000hdata segment: 30020h – 4001Fh

PA = 30020h + 0000h = 30020h → AL = 5Ah. 3000h:0020h and 3002h:0000h are the same byte.

DS3002hoffsetFFFFhPA4001Fhbyte5AhPA = DS × 10h + offset = 30020h + FFFFhdata segment: 30020h – 4001Fh

SI = FFFFh, the largest offset in the segment: PA = 30020h + FFFFh = 4001Fh. 5Ah is written to the last byte of the segment.

mov ax, 3000h
mov ds, ax
mov bx, 0020h
mov byte ptr [bx], 5Ah
mov ax, 3002h
mov ds, ax
mov al, [0000h]
mov si, 0FFFFh
mov [si], al

Classic Question · Segmented Memory

Question 14: Normalization

The physical address 4B7C9h is given.

  1. What is the (normalized) segment:offset form with the offset in the range 0–Fh?
  2. If DS = 4000h, what must the offset be to access this byte?
  3. With DS = 3000h, can this byte be accessed through DS?
  4. How many different segment:offset forms does this physical address have?
Show answer
  1. The first 4 digits are the segment, the last digit the offset: 4B7Ch:0009h.
  2. 4B7C9h − 40000h = B7C9h → 4000h:B7C9h.
  3. No: 4B7C9h − 30000h = 1B7C9h, which does not fit in 16 bits (FFFFh). Segment 3000h covers 30000h–3FFFFh.
  4. Shifting the segment in steps of 16 bytes, as long as the offset stays within 0000h–FFFFh: 4096 forms (3B7Dh:FFF9h … 4B7Ch:0009h).

Multiple Choice · Segmented Memory

Question 15: Same Address, Different Pairs

For the physical address 2A3F0h, which of the following segment:offset pairs does not point to it?

A: 2A30:0F00 → 2A300h + 0F00h = 2B200h. The others: 2A3F0h + 0000h; 2A000h + 03F0h; 20000h + A3F0h: all equal 2A3F0h. The segment value is extended with a 0 on the right (× 10h) and added to the offset; the offset is not shifted.

Step-by-Step Trace · Segmented Memory

Question 16: Wraparound in Real Mode

In real mode, to which physical address does the logical address FFFFh:0020h correspond on the 8086? What changes on an 80286 with the A20 line enabled?

segmentFFFFoffset0020

Logical address FFFFh:0020h. Both parts are 16 bits, i.e. 4 hexadecimal digits.

segment × 10hFFFF0offset0020

× 10h = appending a 0 on the right: base FFFF0h. A segment base is always a multiple of 16.

segment × 10hFFFF0+ offset00020total100010

FFFF0h + 00020h = 100010h: the total is 21 bits, exceeding 1 MB (FFFFFh).

total1000108086 (20 lines)00010

The 8086 has no A20 line: the top bit is dropped and the address wraps around to 00010h. An 80286 with the A20 line enabled accesses 100010h, just above 1 MB.

segment = 0FFFFh
offset  = 0020h
base    = segment × 10h
pa      = base + offset
pa      = pa AND 0FFFFFh ; 20 lines

Multiple Choice · Segmented Memory

Question 17: The Default Segment

If no segment prefix is written, which of the following instructions accesses memory through the SS segment?

B: Every address containing BP uses the SS segment by default; BP is meant for accessing parameters and local variables in the stack frame. BX, SI, DI and a direct address use the DS segment. The default can be changed by writing a prefix: MOV AL, DS:[BP+2].

Multiple Choice · Segmented Memory

Question 18: Memory Accessible at Once

Without ever changing the segment registers, how much memory can an 8086 program access directly at most?

C: Four segments are active at the same time: CS, DS, SS and ES; each covers at most 64 KB with a 16-bit offset. If the segments are placed apart, 4 × 64 KB = 256 KB can be accessed; if they overlap, less. For the rest of the 1 MB, a segment register has to be loaded with a new value.

The End

Chapter 2.1: 8086 Architecture: Study Questions
Lecture slides: Chapter 2.1: 8086 Architecture · Lecture notes
1 / 1 Sercan KÜLCÜ. All rights reserved.