Original BCA Nepal study material. All nine units and their topic order follow the 2025 BCA152 outline; explanations and worked examples are our own, not official TU wording.

How to use this guide

This course bridges microprocessor programming (8085/8086) and computer architecture (CPU design, memory, I/O, pipelining). The exam typically has: 8085 assembly programming (trace/write), architecture diagrams (block diagrams, timing), numerical problems (Booth multiplication, pipeline speedup), and comparative questions (RISC vs CISC, hardwired vs microprogrammed).

Master these procedures: 8085 instruction timing diagrams, assembly programming patterns (loops, arrays, subroutines), 8086 segmentation arithmetic, control unit design steps, Booth algorithm, DMA transfer modes, pipeline hazard resolution.

Contents

  1. Unit 1: Introduction to Microprocessor
  2. Unit 2: 8085 Microprocessor
  3. Unit 3: 8086 Microprocessor
  4. Unit 4: Basic Computer Architecture and Design
  5. Unit 5: Microprogrammed Control Unit
  6. Unit 6: Central Processing Unit
  7. Unit 7: Computer Arithmetic
  8. Unit 8: Input and Output Organization and Memory Organization
  9. Unit 9: Pipelining

Unit 1: Introduction to Microprocessor

Teaching hours: 3

Topics in outline order

  1. Definition of microprocessor
  2. Components: registers, ALU, control and timing, system buses (address, data, control)
  3. Microprocessor system with bus organization
  4. Application of MP

Explanation

1. Definition of microprocessor

A microprocessor is a programmable, clock-driven, register-based electronic device that reads binary instructions from memory, accepts binary data as input, processes data according to those instructions, and provides results as output. It is the central processing unit (CPU) of a microcomputer, fabricated on a single IC (or a few ICs).

Key characteristics:

  • Programmable: Executes a stored sequence of instructions (program).
  • Clock-driven: Operations synchronised by a clock signal.
  • Register-based: Uses internal registers for fast temporary storage.
  • Binary: Processes data in binary (0/1) representation.

2. Components

Component Function
Registers Fast temporary storage for data, addresses, status. Includes accumulator, general-purpose, index, stack pointer, program counter, flags.
ALU (Arithmetic Logic Unit) Performs arithmetic (add, subtract, increment, decrement) and logic (AND, OR, XOR, NOT, compare, shift, rotate) operations.
Control & Timing Unit Generates control signals for instruction fetch, decode, execute; manages timing (T-states, machine cycles).
System Buses Address bus (unidirectional, selects memory/I/O), Data bus (bidirectional, transfers data), Control bus (carries read/write/interrupt signals).

3. Microprocessor system with bus organization

A minimal microprocessor system consists of:

  • Microprocessor (CPU)
  • Memory (ROM for program, RAM for data)
  • I/O devices (keyboard, display, ports)
  • System bus connecting all three
        Address Bus (16-bit for 8085)
    ┌────────────────────────────────┐
    │        MICROPROCESSOR          │
    │  ┌─────┐  ┌─────┐  ┌─────┐    │
    │  │ ALU │  │Regs │  │ CU  │    │
    │  └─────┘  └─────┘  └─────┘    │
    └────────────────────────────────┘
         │           │           │
      Data Bus   Control Bus  (Address out)
         │           │
    ┌────┴────┐ ┌────┴────┐
    │  MEMORY │ │   I/O   │
    │ (ROM/RAM)│ │ DEVICES │
    └─────────┘ └─────────┘

Bus operation:

  1. CPU places address on address bus
  2. CPU asserts control signals (RD/WR, IO/M)
  3. Memory/I/O places/accepts data on data bus
  4. CPU reads/writes data

4. Applications of microprocessor

  • Embedded systems: Washing machines, microwave ovens, automotive ECUs, industrial controllers.
  • Personal computers: Desktops, laptops (x86, ARM).
  • Mobile devices: Smartphones, tablets (ARM).
  • Instrumentation: Medical devices, test equipment, data loggers.
  • Communication: Routers, modems, base stations.
  • Consumer electronics: Smart TVs, gaming consoles, wearables.

Key terms

Microprocessor · ALU · register · bus · address bus · data bus · control bus · clock · instruction cycle · fetch · decode · execute

Revision points

  • Microprocessor = CPU on a chip; microcontroller = CPU + memory + I/O on a chip.
  • Address bus width determines addressable memory (16-bit → 64 KB for 8085).
  • Data bus width determines word size (8-bit for 8085).
  • Control bus carries timing and status signals (not data).

Practice questions

  1. Define microprocessor and list its three main components.
  2. What is the difference between address bus and data bus? Why is address bus unidirectional?
  3. A microprocessor has a 16-bit address bus and 8-bit data bus. What is its maximum addressable memory?
  4. Draw the block diagram of a basic microprocessor system showing bus connections.

Unit 2: 8085 Microprocessor

Teaching hours: 12

Topics in outline order

  1. Functional block diagram, pin configuration, description of each block; registers, flags (description of each flag); multiplexed address-data bus (AD0-AD7); timing and control unit; interrupts (introduction only); addressing modes; instruction cycle, machine cycle (opcode fetch, memory read, memory write) and T states; timing diagram of MOV, LDA, STA, MVI
  2. 8085 instruction set: 2.1 Data transfer: MOV, MVI, STA, LDA, LXI, LDAX, STAX, XCHG 2.2 Arithmetic: ADD, ADI, ADC, SUB, SUI, SBB, INR, DCR, INX, DCX 2.3 Logic: ANA, ANI, ORA, ORI, XRA, XRI, CMA, CMP 2.4 Branching: JMP, JNZ, JZ, JNC, JC
  3. Basic assembly language programming using 8085 instruction sets: addition (8 and 16 bit), subtraction (8 and 16 bit), multiplication (8 bit) and division (8 bit), simple sequence program, array searching using branching and looping

2.1 8085 Architecture and Pin Configuration

Functional block diagram

The 8085 is an 8-bit microprocessor with:

  • 8-bit data bus, 16-bit address bus (A0-A15), multiplexed AD0-AD7 (lower address + data)
  • Registers: Accumulator (A, 8-bit), Flags (F, 8-bit), B, C, D, E, H, L (8-bit each), Stack Pointer (SP, 16-bit), Program Counter (PC, 16-bit)
  • ALU: 8-bit arithmetic and logic
  • Timing & Control: Generates ALE, RD, WR, IO/M, S0, S1, READY, HOLD, HLDA, INTR, RST 5.5/6.5/7.5, TRAP, RESET IN/OUT, CLK OUT
  • Interrupt control: Serial I/O (SID, SOD)

Registers

Register Size Purpose
A (Accumulator) 8-bit Primary operand/result for ALU ops
F (Flags) 8-bit Status flags (S, Z, AC, P, CY)
B, C, D, E, H, L 8-bit each General purpose; pairs BC, DE, HL for 16-bit
SP (Stack Pointer) 16-bit Points to top of stack in memory
PC (Program Counter) 16-bit Holds address of next instruction

Register pairs: BC, DE, HL (16-bit). HL often used as memory pointer.

Flags (F register)

Bit Flag Name Set when
7 S Sign MSB of result = 1 (negative in 2's complement)
6 Z Zero Result = 0
5 - - Reserved
4 AC Auxiliary Carry Carry from bit 3 to bit 4 (BCD arithmetic)
3 - - Reserved
2 P Parity Result has even number of 1s
1 - - Reserved
0 CY Carry Carry out of MSB (unsigned overflow)

Swipe to see all columns

Pin configuration (40-pin DIP)

Pin Name Function
1-2 X1, X2 Crystal inputs (6 MHz crystal for 3 MHz internal clock)
3 RESET OUT Reset output for peripherals
4 SOD Serial output data
5 SID Serial input data
6 TRAP Non-maskable interrupt (highest priority)
7-9 RST 7.5, RST 6.5, RST 5.5 Vectored maskable restart interrupts
10 INTR Maskable interrupt request
11 INTA Interrupt acknowledge
12-19 AD0-AD7 Multiplexed address/data bus (low byte)
20 VSS Ground
21-23 A8-A10 High byte of address bus
24 IO/M I/O (1) or Memory (0) indicator
25 ALE Address Latch Enable (latches AD0-AD7 → address)
26 WR Write (active low)
27 RD Read (active low)
28 S1 Status 1
29 S0 Status 0
30 RESET IN Reset input (active low)
31 CLK OUT System clock output
32 HLDA Hold acknowledge
33 HOLD DMA request
34 READY Wait state request (slow memory)
35-39 A15-A11 High byte of address bus
40 VCC +5V

Multiplexed address-data bus (AD0-AD7)

The lower 8 address bits (A0-A7) and 8 data bits (D0-D7) share the same 8 pins.

  • T1 (first T-state): ALE = 1, AD0-AD7 carry A0-A7. External latch (74LS373) captures address on ALE falling edge.
  • T2/T3: AD0-AD7 carry data (D0-D7) for read/write.

This saves pins but requires external demultiplexing latch.

Timing and control unit

Generates control signals based on instruction and machine cycle type. Key signals:

  • ALE: Asserted in T1 of every machine cycle to latch address.
  • RD (active low): Asserted during read cycles (memory read, I/O read, opcode fetch).
  • WR (active low): Asserted during write cycles (memory write, I/O write).
  • IO/M: High for I/O cycles, low for memory cycles.
  • S1, S0: Status bits encoding machine cycle type.
S1 S0 IO/M Machine Cycle
1 1 0 Opcode Fetch
1 0 0 Memory Read
0 1 0 Memory Write
1 1 1 I/O Read
0 1 1 I/O Write
0 0 1 Interrupt Acknowledge

Swipe to see all columns

Interrupts (introduction)

Interrupt Type Priority Vector Address Notes
TRAP Non-maskable 1 (highest) 0024H Edge + level triggered
RST 7.5 Maskable 2 003CH Rising edge triggered
RST 6.5 Maskable 3 0034H Level triggered
RST 5.5 Maskable 4 002CH Level triggered
INTR Maskable 5 (lowest) External Requires INTA, external device supplies RST/CALL

Swipe to see all columns

Masking: SIM instruction masks RST 5.5, 6.5, 7.5. EI/DI enable/disable all maskable interrupts.

Addressing modes

  1. Immediate: Operand in instruction (MVI A, 05H)
  2. Register: Operand in register (MOV A, B)
  3. Direct: 16-bit address in instruction (LDA 2050H)
  4. Register indirect: Address in register pair (MOV A, M using HL)
  5. Implied: Operand implicit (CMA, RAL)

Instruction cycle, machine cycle, T-states

  • Instruction cycle: Time to fetch and execute one instruction.
  • Machine cycle: One bus access (opcode fetch, memory read/write, I/O read/write). 1-6 T-states.
  • T-state: One clock period. Basic timing unit.

Example: MOV A, B (1-byte, register addressing)

  • 1 machine cycle: Opcode fetch (4 T-states)
  • Total: 4 T-states = 1.33 μs at 3 MHz

Example: LDA 2050H (3-byte, direct addressing)

  • M1: Opcode fetch (4 T) — reads 3A
  • M2: Memory read (3 T) — reads low byte 50H
  • M3: Memory read (3 T) — reads high byte 20H
  • Total: 13 T-states = 4.33 μs

Timing diagrams

Opcode Fetch (4 T-states):

T1        T2        T3        T4
CLK  ──┐  └────┐  └────┐  └────┐
ALE  ────┐     └───────────────
AD0-7 A0-A7  ────── Opcode ────
A8-15 A8-A15 ──────────────────
RD      ─────┐  └───────────────
WR      ────────────────────────
IO/M    ──────────────────────── (0)
S1,S0   1,1 ────────────────────

Memory Read (3 T-states):

T1        T2        T3
CLK  ──┐  └────┐  └────┐
ALE  ────┐     └───────
AD0-7 A0-A7  ──── Data ──
A8-15 A8-A15 ────────────
RD      ─────┐  └───────
WR      ────────────────
IO/M    ──────────────── (0)

Memory Write (3 T-states):

T1        T2        T3
CLK  ──┐  └────┐  └────┐
ALE  ────┐     └───────
AD0-7 A0-A7  ──── Data ──
A8-15 A8-A15 ────────────
RD      ────────────────
WR      ─────┐  └───────
IO/M    ──────────────── (0)

STA 2050H timing (13 T-states): Opcode fetch 4T + memory read 3T + memory read 3T + memory write 3T.

Cycle:   M1 Opcode Fetch   M2 Memory Read    M3 Memory Read    M4 Memory Write
T-state: T1 T2 T3 T4        T1 T2 T3          T1 T2 T3          T1 T2 T3
CLK      ──┐└─┐└─┐└─┐        ──┐└─┐└─┐          ──┐└─┐└─┐          ──┐└─┐└─┐
ALE      ──┐└──────────       ──┐└─────            ──┐└─────            ──┐└─────
AD0-7    A0-A7 32H            A0-A7 50H           A0-A7 20H           A0-A7 Acc
A8-15    A8-A15 ───────────   A8-A15 20H          A8-A15 20H          A8-A15 20H
RD       ─────┐└───────────   ─────┐└─────         ─────┐└─────         ─────────────
WR     ─────────────────────── ─────────────────── ─────────────────── ─────┐└─────
IO/M   ─────────────────────── (0)                 (0)                 (1)
S1,S0  1,1 ─────────────────── 1,0 ───────────────  0,1 ───────────────  0,1 ───────────────

MVI r, data timing (7 T-states): Opcode fetch 4T + memory read 3T.

Cycle:   M1 Opcode Fetch    M2 Memory Read
T-state: T1 T2 T3 T4        T1 T2 T3
CLK      ──┐└─┐└─┐└─┐        ──┐└─┐└─┐
ALE      ──┐└──────────       ──┐└─────
AD0-7    A0-A7 MVI op         A0-A7 data
A8-15    A8-A15 ───────────   A8-A15 ───────────
RD       ─────┐└───────────   ─────┐└─────
WR     ─────────────────────── ───────────────────
IO/M   ─────────────────────── (0)
S1,S0  1,1 ─────────────────── 1,0 ───────────────

2.2 8085 Instruction Set

Data Transfer Instructions

Mnemonic Operand Description Bytes T-states Flags
MOV Rd, Rs Copy Rs → Rd 1 4/7* None
MVI Rd, data Load immediate to Rd 2 7/10* None
LXI RP, data Load immediate to reg pair 3 10 None
LDA addr Load A from memory (direct) 3 13 None
STA addr Store A to memory (direct) 3 13 None
LHLD addr Load HL from memory (direct) 3 16 None
SHLD addr Store HL to memory (direct) 3 16 None
LDAX RP Load A from memory (RP indirect) 1 7 None
STAX RP Store A to memory (RP indirect) 1 7 None
XCHG - Exchange HL ↔ DE 1 4 None
SPHL - Copy HL → SP 1 5 None
XTHL - Exchange HL with stack top 1 18 None
PUSH RP Push RP to stack 1 11 None
POP RP Pop stack to RP 1 10 None

Swipe to see all columns

*If operand is M (memory via HL), add 3 T-states.

Arithmetic Instructions

Mnemonic Operand Description Bytes T-states Flags
ADD R/M A ← A + R/M 1 4/7 All
ADC R/M A ← A + R/M + CY 1 4/7 All
ADI data A ← A + data 2 7 All
ACI data A ← A + data + CY 2 7 All
SUB R/M A ← A - R/M 1 4/7 All
SBB R/M A ← A - R/M - CY 1 4/7 All
SUI data A ← A - data 2 7 All
SBI data A ← A - data - CY 2 7 All
INR R/M R/M ← R/M + 1 1 4/10 All except CY
DCR R/M R/M ← R/M - 1 1 4/10 All except CY
INX RP RP ← RP + 1 1 5 None
DCX RP RP ← RP - 1 1 5 None
DAD RP HL ← HL + RP 1 10 CY only

Swipe to see all columns

Note: ADD/ADC/SUB/SBB affect all flags. INR/DCR affect all except CY. INX/DCX affect no flags. DAD affects only CY.

Logic Instructions

Mnemonic Operand Description Bytes T-states Flags
ANA R/M A ← A ∧ R/M 1 4/7 S, Z, P, CY=0, AC
ANI data A ← A ∧ data 2 7 S, Z, P, CY=0, AC
ORA R/M A ← A ∨ R/M 1 4/7 S, Z, P, CY=0, AC
ORI data A ← A ∨ data 2 7 S, Z, P, CY=0, AC
XRA R/M A ← A ⊕ R/M 1 4/7 S, Z, P, CY=0, AC
XRI data A ← A ⊕ data 2 7 S, Z, P, CY=0, AC
CMA - A ← A' (complement) 1 4 None
CMP R/M Compare A with R/M (A - R/M) 1 4/7 All
CPI data Compare A with data 2 7 All
RLC - Rotate A left (bit 7→CY, CY→bit 0) 1 4 CY
RRC - Rotate A right (bit 0→CY, CY→bit 7) 1 4 CY
RAL - Rotate A left through CY 1 4 CY
RAR - Rotate A right through CY 1 4 CY

Swipe to see all columns

Branching Instructions

Mnemonic Operand Description Bytes T-states Flags
JMP addr Unconditional jump 3 10 None
Jcond addr Conditional jump (JZ, JNZ, JC, JNC, JP, JM, JPE, JPO) 3 7/10 None
CALL addr Unconditional call 3 17 None
Ccond addr Conditional call 3 9/17 None
RET - Return from subroutine 1 10 None
Rcond - Conditional return 1 6/11 None
RST n Restart (software interrupt, n=0-7) 1 11 None
PCHL - Jump to address in HL 1 5 None

Swipe to see all columns

Conditional suffixes:

  • Z: Zero flag set (Z=1)
  • NZ: Zero flag clear (Z=0)
  • C: Carry set (CY=1)
  • NC: Carry clear (CY=0)
  • P: Parity even (P=1)
  • M: Sign negative (S=1)
  • PE: Parity even (P=1)
  • PO: Parity odd (P=0)

2.3 Assembly Language Programming

8-bit addition

; Add two 8-bit numbers at 2000H and 2001H, store result at 2002H
LXI H, 2000H    ; HL = 2000H
MOV A, M        ; A = [2000H]
INX H           ; HL = 2001H
ADD M           ; A = A + [2001H]
INX H           ; HL = 2002H
MOV M, A        ; [2002H] = A
HLT

16-bit addition (using DAD)

; Add two 16-bit numbers at (2000H,2001H) and (2002H,2003H), result at (2004H,2005H)
LHLD 2000H      ; HL = first 16-bit number
XCHG            ; DE = HL, HL free
LHLD 2002H      ; HL = second 16-bit number
DAD D           ; HL = HL + DE
SHLD 2004H      ; Store result
HLT

8-bit subtraction

; Subtract [2001H] from [2000H], result at 2002H
LXI H, 2000H
MOV A, M        ; A = minuend
INX H
SUB M           ; A = A - [2001H]
INX H
MOV M, A        ; Store result
HLT

16-bit subtraction

; Subtract (DE) from (HL), result in HL
; Assumes HL ≥ DE (no borrow handling shown)
MOV A, L        ; Low byte
SUB E           ; A = L - E
MOV L, A        ; Result low
MOV A, H        ; High byte
SBB D           ; A = H - D - borrow
MOV H, A        ; Result high

8-bit multiplication (repeated addition)

; Multiply [2000H] × [2001H], 16-bit result at 2002H,2003H
LXI H, 2000H
MOV B, M        ; B = multiplier
INX H
MOV C, M        ; C = multiplicand
MVI D, 00H      ; High byte of result
MVI A, 00H      ; Low byte of result (accumulator)
MULT_LOOP:
    ADD C       ; A = A + C
    JNC NO_CARRY
    INR D       ; Handle carry to high byte
NO_CARRY:
    DCR B       ; Decrement multiplier
    JNZ MULT_LOOP
INX H
MOV M, A        ; Store low byte
INX H
MOV M, D        ; Store high byte
HLT

8-bit division (repeated subtraction)

; Divide [2000H] by [2001H], quotient at 2002H, remainder at 2003H
LXI H, 2000H
MOV A, M        ; A = dividend
INX H
MOV B, M        ; B = divisor
MVI C, 00H      ; Quotient counter
DIV_LOOP:
    CMP B       ; Compare A with B
    JC DONE     ; If A < B, done
    SUB B       ; A = A - B
    INR C       ; Increment quotient
    JMP DIV_LOOP
DONE:
    INX H
    MOV M, C    ; Store quotient
    INX H
    MOV M, A    ; Store remainder
    HLT

Array searching (linear search)

; Search for value in [2000H] in array at 2100H (length at 2001H)
; If found, store index at 2002H; else store FFH
LXI H, 2100H    ; HL = array base
MOV C, M        ; C = length (assume at 2001H, adjust)
LDA 2000H       ; A = search value
MVI B, 00H      ; B = index
SEARCH_LOOP:
    CMP M       ; Compare A with [HL]
    JZ FOUND
    INX H
    INR B
    DCR C
    JNZ SEARCH_LOOP
    MVI B, FFH  ; Not found
FOUND:
    STA 2002H   ; Store index/FFH
    HLT

Key terms

Accumulator · flags · program counter · stack pointer · register pair · multiplexed bus · ALE · machine cycle · T-state · opcode fetch · addressing mode · immediate · direct · register indirect · implied · DAD · INX · DCX · conditional jump · subroutine · stack · PUSH · POP

Revision points

  • 8085 is 8-bit data, 16-bit address, multiplexed AD0-AD7.
  • Flags: S, Z, AC, P, CY. Know which instructions affect which flags.
  • MOV A, M takes 7 T-states (not 4) because of memory read.
  • DAD is the only 16-bit add; affects only CY.
  • INX/DCX don't affect flags — can't use for loop termination directly.
  • Conditional jumps: 10 T-states if taken, 7 if not.
  • CALL/RET use stack; SP decrements on PUSH/CALL, increments on POP/RET.

Practice questions

  1. Draw the timing diagram for STA 2050H (opcode 32H). Show ALE, RD, WR, AD0-AD7, A8-A15 for all machine cycles.
  2. Write a program to find the largest number in an array of 10 bytes at 3000H.
  3. Explain the function of ALE and why it is needed.
  4. What is the difference between JMP and CALL? How does the stack change?
  5. Trace the flags after: MVI A, 80H / ADD A (result = 00H, CY=1, Z=1, S=0, P=1, AC=1).
  6. Write a subroutine to multiply two 8-bit numbers using repeated addition.

Unit 3: 8086 Microprocessor

Teaching hours: 4

Topics in outline order

  1. Logical block diagram, bus interface and execution units, flags, pipeline concept, memory segmentation, and segment registers

3.1 8086 Architecture

The 8086 is a 16-bit microprocessor (16-bit data bus, 20-bit address bus → 1 MB memory). It uses memory segmentation to address 1 MB with 16-bit registers.

Logical block diagram

The 8086 has two independent processing units:

┌─────────────────────────────────────────────────────────┐
│                   8086 CPU                              │
│  ┌──────────────────┐         ┌──────────────────┐     │
│  │  BUS INTERFACE   │         │  EXECUTION UNIT  │     │
│  │  UNIT (BIU)      │         │  (EU)            │     │
│  │                  │         │                  │     │
│  │  • Segment regs  │◄───────►│  • General regs  │     │
│  │    CS, DS, SS, ES│   Bus   │    AX, BX, CX, DX│     │
│  │  • Instruction   │         │  • Pointer/Index │     │
│  │    queue (6-byte)│         │    SI, DI, BP, SP│     │
│  │  • Address       │         │  • ALU (16-bit)  │     │
│  │    adder         │         │  • Flags         │     │
│  │  • Bus control   │         │  • Control unit  │     │
│  └──────────────────┘         └──────────────────┘     │
└─────────────────────────────────────────────────────────┘

BIU (Bus Interface Unit): Handles all bus operations — instruction fetch, memory read/write, I/O read/write. Contains:

  • Segment registers: CS, DS, SS, ES (16-bit each)
  • Instruction pointer (IP): 16-bit, offset within code segment
  • Instruction queue: 6-byte prefetch queue (pipelining)
  • Address adder: Computes 20-bit physical address

EU (Execution Unit): Executes instructions. Contains:

  • General registers: AX, BX, CX, DX (16-bit, each split into 8-bit halves: AH/AL, BH/BL, CH/CL, DH/DL)
  • Pointer/Index registers: SI (Source Index), DI (Destination Index), BP (Base Pointer), SP (Stack Pointer)
  • Flags register: 16-bit (9 active flags)
  • ALU: 16-bit arithmetic/logic
  • Control unit: Decodes and executes instructions

Pipeline concept

The 8086 uses instruction prefetching — while EU executes current instruction, BIU fetches next instructions into the 6-byte queue. This overlaps fetch and execute, improving throughput.

  • Queue operation: BIU fetches when bus is free and queue has space (2+ bytes empty).
  • EU reads from queue when it needs next instruction byte.
  • Jump/call flushes queue (prefetched instructions invalid).
  • Benefit: Reduces wait states; EU rarely waits for fetch.

Flags register (16-bit, 9 active)

Bit Flag Name Description
0 CF Carry Flag Carry out of MSB (unsigned overflow)
2 PF Parity Flag Even parity of low byte of result
4 AF Auxiliary Carry Carry from bit 3 to 4 (BCD)
6 ZF Zero Flag Result = 0
7 SF Sign Flag MSB of result = 1 (negative)
8 TF Trap Flag Single-step mode (debug)
9 IF Interrupt Flag Enables maskable interrupts (INTR)
10 DF Direction Flag String ops: 0=auto-increment, 1=auto-decrement
11 OF Overflow Flag Signed overflow (2's complement)

Swipe to see all columns

New flags vs 8085: TF (trap), IF (interrupt enable), DF (direction), OF (overflow).

Memory segmentation

Physical address (20-bit) = Segment × 16 + Offset (both 16-bit).

Segment register (16-bit) × 10H (shift left 4) + Offset (16-bit) = Physical address (20-bit)

Example: CS = 1234H, IP = 0056H → Physical = 1234H × 10H + 0056H = 12340H + 0056H = 12396H

Segments:

  • Code Segment (CS): Instructions. IP = offset. CS:IP = next instruction.
  • Data Segment (DS): Default for data access (MOV AX, [BX]).
  • Stack Segment (SS): Stack. SS:SP = top of stack.
  • Extra Segment (ES): Extra data, used by string instructions (destination).

Segment overlap: Segments can overlap. Different segment:offset pairs can map to same physical address.

  • Example: 1000H:0010H → 10000H + 0010H = 10010H; 0FF0H:0110H → 0FF00H + 0110H = 10010H. Both pairs map to physical 10010H.

Advantages: 1 MB addressing with 16-bit registers; relocation; protection (conceptual). Disadvantages: Complexity; 64 KB segment limit; segment arithmetic needed for large arrays.

Segment registers

Register Purpose Default Offset Register
CS Code segment IP
DS Data segment BX, SI, DI
SS Stack segment SP, BP
ES Extra segment DI (string destination)

Segment override prefix: Use ES:, CS:, SS:, DS: before memory operand to override default segment.


Key terms

BIU · EU · prefetch queue · pipelining · segmentation · physical address · segment register · offset · CS · DS · SS · ES · IP · SP · BP · SI · DI · flags (CF, PF, AF, ZF, SF, TF, IF, DF, OF)

Revision points

  • 8086 = 16-bit data, 20-bit address (1 MB), segmented memory.
  • BIU fetches, EU executes — overlapping via 6-byte queue.
  • Physical address = Segment × 16 + Offset.
  • Four segments (CS, DS, SS, ES), each 64 KB max.
  • New flags: TF (single-step), IF (interrupt enable), DF (string direction), OF (signed overflow).
  • Queue flushed on control transfer (JMP, CALL, INT).

Practice questions

  1. Calculate physical address for CS=2000H, IP=0100H; DS=3000H, BX=0020H; SS=4000H, SP=0010H.
  2. Explain how the 6-byte prefetch queue improves performance. What happens on a JMP?
  3. What is the maximum size of a segment? Why?
  4. Differentiate between 8085 and 8086 flags. Which are new in 8086?
  5. If DS=1234H and SI=0056H, what is the physical address of [SI]? What if ES override is used?

Unit 4: Basic Computer Architecture and Design

Teaching hours: 6

Topics in outline order

  1. Stored program organization, computer registers, common bus system, instruction set, timing and control - instruction cycle
  2. Arithmetic micro-operations: addition, subtraction, increment, decrement; logic micro-operations: AND, OR, NOT, NAND, NOR, XOR; shift micro-operations: logical, circular and arithmetic
  3. Hardwired vs microprogrammed CU, control memory, address sequencing, micro-operation, microinstruction, microinstruction format, micro-program: symbolic and binary micro-program (FETCH)

4.1 Stored Program Organization

Von Neumann architecture: Program and data stored in same memory. CPU fetches instructions sequentially (unless branch).

Computer registers (typical):

Register Bits Function
PC (Program Counter) 12-16 Address of next instruction
AR (Address Register) 12-16 Memory address for read/write
DR (Data Register) 16 Data to/from memory
AC (Accumulator) 16 ALU operand/result
IR (Instruction Register) 16 Current instruction (opcode + address)
TR (Temporary Register) 16 Temporary storage
INPR/OUTR 8 Input/output registers
SC (Sequence Counter) 4 Counts T-states in cycle

Common bus system

Multiple registers connect to a shared bus via tri-state buffers. Control signals enable one register output at a time.

Register A ──┐
Register B ──┤
Register C ──┼──► [Common Bus] ◄──► Memory, ALU, etc.
Register D ──┤
     ...     └── Control signals select source/destination

Bus selection: Multiplexers select source; decoder selects destination (LD signal).

Instruction format

Typical 16-bit instruction:

| 15 14 13 12 | 11 ... 0 |
|   Opcode    |  Address |
  • Opcode (4 bits): 16 possible operations.
  • Address (12 bits): Memory address (4096 words).

Instruction set example (basic computer):

  • Memory reference: AND, ADD, LDA, STA, BUN, BSA, ISZ
  • Register reference: CLA, CLE, CMA, CME, CIR, CIL, INC, SPA, SNA, SZA, SZE, HLT
  • I/O reference: INP, OUT, SKI, SKO, ION, IOF

Timing and control - instruction cycle

Instruction cycle phases:

  1. Fetch: PC → AR, Memory → IR, PC ← PC + 1
  2. Decode: Opcode → control signals
  3. Execute: Perform operation (may involve more memory cycles)
  4. Interrupt check: If interrupt enabled and requested, branch to ISR

Fetch cycle micro-operations (symbolic):

T0: AR ← PC
T1: IR ← M[AR], PC ← PC + 1
T2: Decode IR(15-12), AR ← IR(11-0) (for memory-ref)

4.2 Micro-operations

Arithmetic micro-operations

Operation Symbolic Description
Addition R3 ← R1 + R2 Add R1 and R2, store in R3
Subtraction R3 ← R1 - R2 R1 - R2 (using 2's complement)
Increment R1 ← R1 + 1 Add 1
Decrement R1 ← R1 - 1 Subtract 1
Add with carry R3 ← R1 + R2 + C For multi-precision
Subtract with borrow R3 ← R1 - R2 - C For multi-precision

2's complement subtraction: R1 - R2 = R1 + (R2' + 1)

Logic micro-operations

Operation Symbolic Description
AND R3 ← R1 ∧ R2 Bitwise AND
OR R3 ← R1 ∨ R2 Bitwise OR
XOR R3 ← R1 ⊕ R2 Bitwise XOR
NOT/Complement R1 ← R1' Bitwise NOT
NAND R3 ← (R1 ∧ R2)' NOT AND
NOR R3 ← (R1 ∨ R2)' NOT OR

Selective operations (using mask):

  • Selective set: R1 ← R1 ∨ R2 (set bits where R2=1)
  • Selective clear: R1 ← R1 ∧ R2' (clear bits where R2=1)
  • Selective complement: R1 ← R1 ⊕ R2 (toggle bits where R2=1)
  • Mask: R1 ← R1 ∧ R2 (clear bits where R2=0)
  • Insert: R1 ← (R1 ∧ R2') ∨ (R3 ∧ R2) (insert R3 bits where R2=1)
  • Compare: R1 ← R1 ⊕ R2 (XOR for equality check)

Shift micro-operations

Type Symbolic Description
Logical left shl R Shift left, 0 → LSB, MSB → carry
Logical right shr R Shift right, 0 → MSB, LSB → carry
Circular left (rotate) cil R MSB → LSB, MSB → carry
Circular right (rotate) cir R LSB → MSB, LSB → carry
Arithmetic left ashl R Shift left, 0 → LSB, MSB → carry, overflow if sign changes
Arithmetic right ashr R Shift right, MSB (sign) preserved, LSB → carry

Arithmetic right preserves sign bit (for signed 2's complement division by 2). Logical shifts fill with 0 (for unsigned). Circular/rotate bits wrap around.


4.3 Control Unit Design

Hardwired control unit

Control signals generated by combinational logic (decoders, gates, flip-flops).

  • Fast: No memory access for control.
  • Inflexible: Changes require hardware redesign.
  • Used in: RISC, simple processors, high-speed units.

Components: Instruction decoder, timing generator (ring counter), control logic (AND/OR gates), flags.

Microprogrammed control unit

Control signals stored in control memory (CM) as microinstructions. A microprogram = sequence of microinstructions.

  • Flexible: Modify microcode to change instruction set.
  • Slower: Extra memory cycle per microinstruction.
  • Used in: CISC, complex instruction sets.

Key concepts:

  • Control memory (CM): ROM/PROM storing microinstructions.
  • Control address register (CAR): Holds address of next microinstruction.
  • Microinstruction: Specifies micro-operations and next address.
  • Micro-operation: Elementary operation (register transfer, ALU op).
  • Microinstruction format: Control bits + next address field.

Address sequencing

How CAR gets next microinstruction address:

  1. Sequential: CAR ← CAR + 1 (default)
  2. Branch: CAR ← address field (conditional/unconditional)
  3. Subroutine: Stack saves return address
  4. Opcode mapping: Instruction opcode → microprogram start address (via mapping ROM)

Microinstruction format (horizontal vs vertical)

Horizontal (wide, parallel): One bit per control signal. Wide (50+ bits), fast, little encoding.

| Control bits (1 per signal) | Next address | Condition |

Vertical (narrow, encoded): Control fields encoded (e.g., 3 bits for 8 ALU ops). Narrower, needs decoder, slower.

| F1 | F2 | F3 | ... | Next address | Condition |

Symbolic microprogram (FETCH routine)

FETCH:  AR ← PC
        CAR ← FETCH1
FETCH1: IR ← M[AR], PC ← PC + 1
        CAR ← FETCH2
FETCH2: AR ← IR(11-0)        ; Address part for memory-ref
        CAR ← MAP            ; Map opcode to micro-routine

Binary microprogram (FETCH) example

Assume: 4-bit opcode, 12-bit address, 20 control signals, 12-bit next address, 4-bit condition.

Address Microinstruction (binary) Meaning
00 000...001 000000000001 0000 AR←PC, next=1, unconditional
01 000...010 000000000010 0000 IR←M[AR], PC←PC+1, next=2
02 000...100 000000000011 0000 AR←IR(11-0), next=3 (MAP)

Key terms

Stored program · Von Neumann · common bus · tri-state buffer · instruction cycle · fetch · decode · execute · micro-operation · arithmetic · logic · shift · hardwired CU · microprogrammed CU · control memory · CAR · microinstruction · address sequencing · mapping · horizontal · vertical · FETCH routine

Revision points

  • Hardwired: fast, fixed. Microprogrammed: flexible, slower.
  • Microinstruction = control bits + next address + condition.
  • Address sequencing: sequential, branch, mapping, subroutine.
  • Fetch cycle: PC→AR, M[AR]→IR, PC←PC+1, decode, map opcode.
  • Arithmetic shifts preserve sign; logical shifts fill with 0.
  • Selective operations use masks (AND, OR, XOR with mask).

Practice questions

  1. List the micro-operations for the fetch cycle of a basic computer.
  2. Differentiate hardwired and microprogrammed control units with a comparison table.
  3. Explain horizontal vs vertical microinstruction format. Give an example of each.
  4. What is the purpose of the mapping ROM in a microprogrammed CU?
  5. Show the symbolic microprogram for an ADD instruction (memory reference).
  6. Perform arithmetic right shift on 11010110 (signed -42). What is the result?

Unit 5: Microprogrammed Control Unit

Teaching hours: 5

Topics in outline order

  1. Microprogrammed control unit

5.1 Microprogrammed Control Unit (Detailed)

This unit expands on the microprogrammed CU concepts from Unit 4.

Control memory organization

  • Control Memory (CM): ROM (typically 1K-4K words, 20-100+ bits wide).
  • Control Address Register (CAR): Holds current microinstruction address.
  • Sequencer: Determines next CAR value (increment, branch, map, stack).
  • Pipeline register: Holds current microinstruction for stable control signals.
          ┌─────────────┐
    CAR ──►│  Control    │──► Microinstruction Register
          │  Memory     │
          └─────────────┘
                 │
        ┌────────┼────────┐
        ▼        ▼        ▼
    Control   Next      Condition
    Signals   Address   Select
        │        │        │
        ▼        ▼        ▼
     CPU/      Sequencer  Flags/
     Memory             Status

Microinstruction format details

Fields typically include:

  1. ALU operation select (4-6 bits): ADD, SUB, AND, OR, XOR, SHIFT, PASS, etc.
  2. Register select (source/destination): Which registers connect to bus/ALU.
  3. Memory control: READ, WRITE, address source.
  4. Bus control: Source/destination for system bus.
  5. External control: I/O, interrupt acknowledge.
  6. Next address field: 10-12 bits for next microinstruction.
  7. Condition select: 3-4 bits (test Z, C, N, O, etc. for conditional branch).

Example horizontal format (56 bits):

| F1(8) | F2(8) | F3(8) | CD(4) | BR(4) | AD(12) | ... |
  • F1, F2, F3: Control fields (ALU, registers, memory, bus)
  • CD: Condition select
  • BR: Branch type (uncond, cond, map, subroutine)
  • AD: Next address

Address sequencing techniques

  1. Incrementer: CAR ← CAR + 1 (default sequential flow).
  2. Branch: CAR ← AD field (unconditional) or CAR ← AD if condition true.
  3. Mapping: Opcode → starting microaddress (via mapping ROM/PLA).
  4. Subroutine call/return: Stack in sequencer saves return address.
  5. Interrupt: Special micro-routine for interrupt handling.

Conditional branching: Test flags (Z, C, N, O) or external conditions. Next address = AD if condition met, else CAR+1.

Microinstruction execution cycle

1. Fetch:   CAR → CM address lines → Microinstruction Register
2. Execute: Control signals → CPU datapath → Micro-operations
3. Update:  Sequencer computes next CAR (based on BR, CD, flags)
4. Repeat

Pipelining: Overlap fetch of next microinstruction with execute of current.

Writing a microprogram: Example (ADD memory to AC)

Assume: AC accumulator, DR data register, AR address register, PC program counter, IR instruction register.

Symbolic:

FETCH0:  AR ← PC
FETCH1:  IR ← M[AR], PC ← PC + 1
FETCH2:  AR ← IR(address)
FETCH3:  CAR ← MAP(IR(opcode))

ADD0:    DR ← M[AR]          ; Read operand
ADD1:    AC ← AC + DR        ; Add to accumulator
ADD2:    CAR ← FETCH0        ; Next instruction

Binary (simplified, assuming horizontal control bits):

Addr ALU Reg Src Reg Dest Mem Bus Next Addr Cond Comment
00 PASS PC AR - - 01 None FETCH0
01 PASS MEM IR, PC+1 RD - 02 None FETCH1
02 PASS IR(ad) AR - - MAP None FETCH2
03 - - - - - MAP None MAP to ADD0
10 PASS MEM DR RD - 11 None ADD0
11 ADD AC, DR AC - - 00 None ADD1, back to FETCH0

Swipe to see all columns

Microprogrammed vs hardwired: Detailed comparison

Aspect Hardwired Microprogrammed
Speed Faster (no CM access) Slower (CM access per microinstruction)
Flexibility Low (hardware change) High (modify microcode)
Complexity Complex logic design Regular structure (CM + sequencer)
Instruction set Simple, fixed Complex, variable (CISC)
Debugging Difficult Easier (microcode trace)
Cost (high volume) Lower Higher (CM area)
Applications RISC, DSP, embedded x86, mainframes, CISC

Design considerations

  • Control memory size: Balance between number of microinstructions and width.
  • Encoding: Horizontal (fast, wide) vs vertical (compact, slower).
  • Sequencing: Efficient next-address logic critical for performance.
  • Subroutine support: Stack depth for micro-subroutines.
  • Interrupt handling: Vectored micro-routines for each interrupt.

Key terms

Control memory · CAR · microinstruction · micro-operation · sequencer · mapping · horizontal · vertical · pipeline register · conditional branch · subroutine · microprogram · FETCH · microcode · control signals · next address field · condition select

Revision points

  • Microprogrammed CU = CM + CAR + Sequencer + Pipeline register.
  • Microinstruction format: control bits + next address + condition.
  • Address sequencing: increment, branch, map, subroutine.
  • Horizontal = 1 bit per signal; vertical = encoded fields.
  • FETCH routine universal; opcode maps to instruction micro-routine.
  • Microprogrammed enables complex CISC instructions (string ops, decimal arithmetic).

Practice questions

  1. Design a microinstruction format for a CPU with 16 registers, 8 ALU ops, 4 memory ops, 3 bus ops. Calculate bits needed for horizontal vs vertical.
  2. Write the symbolic microprogram for a branch instruction (BUN - branch unconditionally).
  3. Explain how conditional branching works in a microprogrammed sequencer.
  4. What is the purpose of the pipeline register in a microprogrammed CU?
  5. Compare the control memory organization for horizontal vs vertical microinstructions.

Unit 6: Central Processing Unit

Teaching hours: 6

Topics in outline order

  1. Introduction, general register organization, stack organization, instruction formats: 3, 2, 1, 0 address instructions
  2. RISC and CISC architecture

6.1 CPU Organization

General register organization

Modern CPUs use multiple general-purpose registers instead of single accumulator.

Register file: Array of registers (16-32 typically) with 2-3 read ports, 1-2 write ports for superscalar.

Register types:

  • Data registers: Hold operands (EAX, EBX, ECX, EDX in x86; R0-R15 in ARM).
  • Address/index registers: Pointers, array indexing (ESI, EDI, EBP, ESP; R0-R15 in ARM).
  • Status registers: Flags, condition codes (EFLAGS, CPSR).
  • Control registers: PC, stack pointer, frame pointer, mode bits.

Advantages of register file vs accumulator:

  • Faster (no memory traffic for temporaries)
  • Compiler optimization (register allocation)
  • Supports pipelining (multiple operands available)

Stack organization

Stack: LIFO structure in memory. SP (Stack Pointer) points to top.

Operations:

  • PUSH: SP ← SP - 1 (or -2 for 16-bit), M[SP] ← data
  • POP: data ← M[SP], SP ← SP + 1 (or +2)

Stack frame (activation record): For subroutine calls.

High address
┌─────────────┐
│ Parameters  │  ← Passed by caller
├─────────────┤
│ Return addr │  ← Pushed by CALL
├─────────────┤
│ Saved regs  │  ← Callee-saved registers
├─────────────┤
│ Local vars  │  ← Allocated by callee
├─────────────┤
│ ...         │
└─────────────┘
Low address (SP grows down)

Stack pointer: Decrements on push (grows toward lower addresses) in most architectures.

Instruction formats

Classification by number of address fields in instruction:

Format Example Operation Operands in Memory
3-address ADD R1, R2, R3 R1 ← R2 + R3 0 (all registers)
2-address ADD R1, R2 R1 ← R1 + R2 0 or 1
1-address ADD X AC ← AC + M[X] 1 (accumulator)
0-address ADD Stack: pop, pop, add, push 0 (stack)

Swipe to see all columns

3-address (RISC-like): ADD R1, R2, R3 — R1 = R2 + R3. Three register fields. 2-address (x86, 68k): ADD R1, R2 — R1 = R1 + R2. Two register/memory fields. 1-address (accumulator): ADD X — AC = AC + M[X]. One address field + implied accumulator. 0-address (stack): ADD — Pop two, add, push result. No address fields (implied stack).

Instruction length trade-off:

  • More addresses → longer instructions → more memory bandwidth.
  • Fewer addresses → more instructions for same task → more fetches.
  • Modern RISC: 3-address, fixed 32-bit.
  • x86: Variable length, 2-address (mostly), complex encoding.

Addressing modes (extended)

Mode Example Effective Address Use Case
Immediate ADD #5 Operand in instruction Constants
Register ADD R1 Operand in register Fast access
Direct ADD 1000 Address in instruction Global variables
Register Indirect ADD (R1) Address in register Pointers, arrays
Indexed ADD X(R1) Address = X + R1 Arrays (base + index)
Based ADD (R1)+ Address = R1, then R1++ Stack, strings
Relative ADD $+10 Address = PC + offset Position-independent code

Swipe to see all columns


6.2 RISC and CISC Architecture

CISC (Complex Instruction Set Computer)

Philosophy: Rich instruction set, complex instructions that do more work per instruction. Close to high-level language constructs.

Characteristics:

  • Large instruction set (100-300+ instructions)
  • Variable-length instructions (1-15 bytes in x86)
  • Many addressing modes (10-20+)
  • Microprogrammed control (complex instructions = microcode)
  • Few registers (8-16 general purpose)
  • Memory-to-memory operations (ADD [mem], [mem])
  • Complex instructions: String move, decimal arithmetic, procedure call with frame setup
  • Emphasis: Reduce semantic gap, code density

Examples: x86 (8086-Pentium), VAX, Motorola 68000, System/360

RISC (Reduced Instruction Set Computer)

Philosophy: Simple instructions, execute fast (1 cycle), rely on compiler optimization. Load/store architecture.

Characteristics:

  • Small instruction set (30-100 instructions)
  • Fixed-length instructions (32-bit typical)
  • Few addressing modes (3-5: register, immediate, displacement)
  • Hardwired control (no microcode)
  • Many registers (32+ general purpose)
  • Load/store architecture: Only LOAD/STORE access memory; ALU ops use registers only.
  • Pipelining friendly: Fixed length, simple decode, 1 cycle per stage.
  • Emphasis: Performance via pipelining, compiler optimization, high clock rate.

Examples: ARM, MIPS, SPARC, PowerPC, RISC-V, DEC Alpha

Detailed comparison

Feature CISC RISC
Instruction count 100-300+ 30-100
Instruction length Variable (1-15 bytes) Fixed (32-bit)
Addressing modes 10-20+ 3-5
Control unit Microprogrammed Hardwired
Registers 8-16 32+
Memory access Many instructions LOAD/STORE only
ALU operands Reg, mem, immediate Registers only
Cycles per instruction 2-10+ (variable) 1 (ideal pipeline)
Pipelining Difficult (variable len) Easy (fixed len, simple)
Code density High (complex insns) Lower (more insns)
Compiler role Less critical Critical (optimization)
Examples x86, VAX, 68k ARM, MIPS, RISC-V

RISC pipeline (5-stage classic)

IF  →  ID  →  EX  →  MEM  →  WB
Fetch Decode Execute Memory Writeback
  • IF: Fetch instruction from PC
  • ID: Decode, read registers
  • EX: ALU operation
  • MEM: Memory access (LOAD/STORE)
  • WB: Write result to register file

Pipeline hazards: Data (RAW, WAR, WAW), Control (branches), Structural (resource conflicts).

Modern trends

  • x86 (CISC) translates to RISC-like micro-ops internally (since Pentium Pro). Micro-op fusion, out-of-order execution, speculative execution.
  • ARM/RISC-V adding complex instructions (NEON SIMD, crypto, virtualization).
  • Convergence: CISC front-end (code density) + RISC back-end (execution efficiency).

Key terms

Register file · stack · stack frame · activation record · 3-address · 2-address · 1-address · 0-address · accumulator · load/store architecture · microprogrammed · hardwired · pipelining · micro-ops · out-of-order · speculative execution · code density · semantic gap

Revision points

  • 3-address: R1←R2+R3; 2-address: R1←R1+R2; 1-address: AC←AC+M[X]; 0-address: stack-based.
  • Stack grows down (SP decrements on push).
  • RISC: fixed 32-bit, load/store, many regs, hardwired, pipelined.
  • CISC: variable length, memory operands, few regs, microcoded.
  • Modern x86 = CISC ISA + RISC microarchitecture (micro-op translation).

Practice questions

  1. Write the instruction sequence for A = B + C in 3-address, 2-address, 1-address, and 0-address machines.
  2. Explain why RISC uses load/store architecture. What is the alternative?
  3. Compare RISC and CISC on: instruction length, addressing modes, control unit, registers, pipelining.
  4. How does modern x86 achieve RISC-like performance while maintaining CISC ISA?
  5. What are the three types of pipeline hazards? Give an example of each.

Unit 7: Computer Arithmetic

Teaching hours: 3

Topics in outline order

  1. Addition and subtraction with signed magnitude data, addition and subtraction with signed 2's complement data, Booth multiplication

7.1 Signed Number Representations

Signed magnitude

  • MSB = sign (0=positive, 1=negative), remaining bits = magnitude.
  • Example (8-bit): +5 = 00000101, -5 = 10000101
  • Two zeros: +0 = 00000000, -0 = 10000000
  • Range: ±(2^(n-1) - 1) = ±127 for 8-bit

Signed 2's complement

  • Positive: same as magnitude. Negative: 2's complement of magnitude.
  • Example (8-bit): +5 = 00000101, -5 = 11111011
  • Single zero: 00000000
  • Range: -2^(n-1) to +2^(n-1)-1 = -128 to +127 for 8-bit
  • Asymmetric: One more negative than positive

Signed 1's complement

  • Negative: 1's complement (invert all bits) of magnitude.
  • Example: +5 = 00000101, -5 = 11111010
  • Two zeros: +0 = 00000000, -0 = 11111111
  • Range: ±127 for 8-bit

7.2 Addition and Subtraction

Signed magnitude addition/subtraction

Rules:

  1. Same signs: Add magnitudes, keep sign.
  2. Different signs: Subtract smaller magnitude from larger, result sign = sign of larger magnitude.
  3. Subtraction: Change sign of subtrahend, then add.

Example: +5 + (-3) (8-bit signed magnitude)

  • +5 = 00000101, -3 = 10000011
  • Signs differ → subtract magnitudes: 5 - 3 = 2
  • Larger magnitude is +5 → result sign = positive
  • Result: +2 = 00000010

Example: -5 + (-3)

  • Both negative → add magnitudes: 5 + 3 = 8, sign = negative
  • Result: -8 = 10001000

Hardware: Requires comparator, adder/subtractor, sign logic. More complex than 2's complement.

2's complement addition/subtraction

Addition: Simple binary addition, discard carry out of MSB.

  • Overflow detection: Carry into MSB ≠ Carry out of MSB (or: same-sign operands → opposite-sign result)

Subtraction: A - B = A + (2's complement of B)

  • Negate B: invert + 1, then add.

Examples (8-bit):

Operation Binary Result Decimal Flags
5 + 3 00000101 + 00000011 00001000 8 OK
-5 + -3 11111011 + 11111101 1 11111000 -8 Discard carry
5 - 3 00000101 + 11111101 1 00000010 2 Discard carry
-5 - 3 11111011 + 11111101 1 11111000 -8 Discard carry
100 + 50 01100100 + 00110010 10010110 -106 Overflow!

Swipe to see all columns

Overflow rule: If two positive numbers yield negative, or two negative yield positive → overflow.

  • Carry into MSB (bit 6→7) XOR Carry out of MSB (bit 7→carry) = 1 → overflow.

1's complement addition/subtraction

Addition: Binary addition + end-around carry (carry out added to LSB). Subtraction: A - B = A + (1's complement of B) + end-around carry.


7.3 Booth Multiplication Algorithm

Booth's algorithm multiplies two signed 2's complement numbers. It examines pairs of bits (Q_i, Q_{i-1}) to decide action, reducing operations for sequences of 1s.

Key idea: A block of 1s in multiplier (e.g., 011110) = 100000 - 000010 = 2^k - 2^m. So instead of 4 additions, do 1 subtraction + 1 addition.

Algorithm (Booth's radix-2)

Registers:

  • M: Multiplicand (sign extended)
  • Q: Multiplier
  • A: Accumulator (initially 0)
  • Q_{-1}: Extra bit (initially 0)
  • Count: Number of bits (n)

Step (repeat n times):

  1. Examine (Q_0, Q_{-1}):
    • 00 → Arithmetic right shift (A, Q, Q_{-1})
    • 01 → A ← A + M, then arithmetic right shift
    • 10 → A ← A - M, then arithmetic right shift
    • 11 → Arithmetic right shift (middle of 1s block)
  2. Decrement count

Final product: (A, Q) combined (2n bits).

Worked example: 5 × (-3) = -15 (4-bit)

M = 0101 (+5), Q = 1101 (-3 in 4-bit 2's complement: 3=0011, invert=1100, +1=1101)

Step Q_0 Q_{-1} Action A Q Q_{-1}
Initial - - - 0000 1101 0
1 1 0 A←A-M (1011), shift 1101 1110 1
2 0 1 A←A+M (0010), shift 0001 0111 0
3 1 0 A←A-M (1100), shift 1110 0011 1
4 1 1 Shift only 1111 0001 1

Swipe to see all columns

Result: A=1111, Q=0001 → 11110001 = -15 (8-bit) ✓

Verification: -15 in 8-bit 2's complement: 15=00001111, invert=11110000, +1=11110001. Matches.

Booth's radix-4 (modified Booth)

Examines 3 bits at a time (Q_i, Q_{i-1}, Q_{i-2}), reduces steps by half. Actions: 0, ±M, ±2M.


Key terms

Signed magnitude · 2's complement · 1's complement · overflow · carry · Booth algorithm · multiplicand · multiplier · arithmetic right shift · end-around carry · radix-2 · radix-4 · recoding

Revision points

  • 2's complement: single zero, asymmetric range, simple add/sub (discard carry).
  • Signed magnitude: two zeros, sign-magnitude separate, complex add/sub.
  • Overflow in 2's complement: same sign operands → opposite sign result.
  • Booth: examines (Q_i, Q_{i-1}) pairs. 01→+M, 10→-M, 00/11→shift only.
  • Arithmetic right shift preserves sign bit (replicates MSB).
  • Booth works for signed 2's complement; reduces additions for 1s blocks.

Practice questions

  1. Add -45 and -78 using 8-bit 2's complement. Show overflow check.
  2. Subtract -23 from 56 using 2's complement.
  3. Multiply 7 × (-5) using Booth's algorithm (5-bit).
  4. Explain why 2's complement is preferred over signed magnitude in computers.
  5. Perform Booth radix-4 encoding for multiplier 011011.

Unit 8: Input and Output Organization and Memory Organization

Teaching hours: 5

Topics in outline order

  1. Introduction to peripheral devices, I/O interface - I/O bus and interface modules, isolated versus memory mapped I/O, interrupt
  2. Direct Memory Access (DMA): introduction, basic DMA procedures (DMA controller only)
  3. Hierarchy of memory system
  4. Primary memory: RAM and ROM, memory address map with examples of address decoding; secondary memory: structure of magnetic disk, cache memory

8.1 I/O Organization

Peripheral devices and I/O interface

Peripheral device: External device (keyboard, display, disk, network) connected via I/O interface.

I/O interface module: Bridges CPU bus and device. Contains:

  • Data registers: Input buffer, output buffer
  • Status register: Ready, error, interrupt enable
  • Control register: Device configuration
  • Device side: Device-specific protocol (serial, parallel, USB, etc.)

I/O bus and interface modules

I/O bus: Shared communication path (like system bus but for I/O). Examples: PCI, PCIe, USB, SATA.

Interface module functions:

  • Buffering: Speed matching (CPU fast, device slow)
  • Error detection: Parity, checksum
  • Timing: Handshaking (strobe/acknowledge)
  • Conversion: Serial ↔ parallel, voltage levels

Isolated vs Memory-mapped I/O

Aspect Isolated I/O Memory-mapped I/O
Address space Separate I/O address space Same as memory address space
Instructions Special IN/OUT instructions Standard LOAD/STORE
Address lines Fewer (8-16 bit I/O address) Full address bus
Control signals IOR, IOW (or IO/M) MEMR, MEMW
Protection Easier (separate space) Needs memory protection
Flexibility Limited instructions Full instruction set on I/O
Example x86 (IN/OUT), 8085 ARM, MIPS, 68000, modern x86 (also)

8085: Isolated I/O (IO/M pin, IN/OUT instructions, 8-bit port address → 256 ports). Modern systems: Mostly memory-mapped (device registers appear in physical address space).

Interrupt-driven I/O

Polling: CPU repeatedly checks status register. Wastes cycles. Interrupt: Device signals CPU when ready. CPU suspends current task, runs ISR.

Interrupt process:

  1. Device asserts interrupt request (INTR)
  2. CPU finishes current instruction, acknowledges (INTA)
  3. Device supplies vector (RST n) or CPU uses fixed vector
  4. CPU pushes PC, flags; jumps to ISR
  5. ISR services device, executes EI/RET
  6. CPU restores PC, flags; resumes

Types:

  • Maskable: Can be disabled (DI/EI, interrupt mask register). Example: INTR, RST 5.5/6.5/7.5.
  • Non-maskable: Cannot be disabled (NMI, TRAP). Critical events (power fail, memory error).
  • Vectored: Device supplies ISR address (RST 5.5/6.5/7.5, TRAP).
  • Non-vectored: CPU uses fixed address (INTR with external hardware).

Priority: TRAP > RST 7.5 > RST 6.5 > RST 5.5 > INTR.


8.2 Direct Memory Access (DMA)

Problem: Programmed I/O and interrupt I/O require CPU to move each byte. Slow for bulk transfer (disk, network).

DMA: Special controller (DMAC) transfers data directly between memory and I/O device without CPU intervention.

DMA Controller (e.g., 8257, 8237)

Registers per channel:

  • Base address register: Starting memory address
  • Base count register: Number of bytes (decrements)
  • Mode register: Transfer mode, direction, priority
  • Status register: Terminal count (TC), update flag

Signals:

  • HOLD: DMAC requests bus from CPU
  • HLDA: CPU grants bus (floats its buses)
  • DREQ: Device requests transfer
  • DACK: DMAC acknowledges device
  • MEMR/MEMW: Memory read/write (from DMAC)
  • IOR/IOW: Device read/write (from DMAC)

DMA Transfer Modes

Mode Description Use Case
Burst (Block) DMAC holds bus until entire block transferred Fast devices, high priority
Cycle Stealing DMAC transfers 1 byte/word, releases bus, repeats Mixed CPU/DMA, lower priority
Demand Device controls timing via DREQ; DMAC transfers while DREQ active Variable-rate devices
Transparent DMAC uses bus only when CPU not using it (idle cycles) Very low priority

Basic DMA Procedure

  1. Setup (CPU): Program DMAC channel with base address, count, mode.
  2. Request (Device): Device asserts DREQ.
  3. Bus Request (DMAC): DMAC asserts HOLD to CPU.
  4. Bus Grant (CPU): CPU finishes current bus cycle, floats buses, asserts HLDA.
  5. Transfer (DMAC): DMAC drives address, control; device drives/accepts data; count decrements.
  6. Completion: When count=0 (TC), DMAC releases HOLD, interrupts CPU (optional).
  7. Resume (CPU): CPU reclaims bus on HLDA deassertion.

Cycle stealing timing:

CPU:  [Instr][Instr]   [Instr][Instr]   [Instr]...
Bus:       │  DMA   │       │  DMA   │
DMAC:       ◄────────►       ◄────────►

8.3 Memory Hierarchy

Principle: Fast, small, expensive memory (registers, cache) close to CPU; slow, large, cheap memory (disk) far from CPU.

CPU
 │
 ├─ Registers (1 cycle, <1 KB)
 │
 ├─ L1 Cache (2-4 cycles, 32-64 KB)
 │
 ├─ L2 Cache (10-20 cycles, 256 KB-1 MB)
 │
 ├─ L3 Cache (30-50 cycles, 4-32 MB, shared)
 │
 ├─ Main Memory (RAM) (100-200 cycles, 4-128 GB)
 │
 └─ Secondary Storage (SSD/HDD) (ms, TB)

Locality of reference:

  • Temporal: Recently accessed likely accessed again (stack, loops).
  • Spatial: Adjacent locations likely accessed (arrays, sequential code).

8.4 Primary Memory

RAM (Random Access Memory)

SRAM (Static RAM): 6 transistors/bit, fast (1-2 ns), no refresh, expensive, low density. Used for caches.

DRAM (Dynamic RAM): 1 transistor + 1 capacitor/bit, slower (50-70 ns), needs refresh (every 64 ms), cheap, high density. Used for main memory.

DRAM organization: Rows × Columns. Access: RAS (Row Address Strobe) → CAS (Column Address Strobe).

  • SDRAM: Synchronous, clocked.
  • DDR SDRAM: Double Data Rate (both clock edges). DDR4/DDR5 current.

ROM (Read-Only Memory)

Type Erasable? Method Use Case
Mask ROM No Factory High-volume firmware
PROM Once Electrical (fuse) Prototyping
EPROM Yes UV light (window) Development
EEPROM Yes Electrical (byte) Configuration
Flash Yes Electrical (block) BIOS, SSD, USB

Swipe to see all columns

Memory address map and address decoding

Address decoding: Selects memory chip based on high address bits.

Example: 64 KB system with 8 KB ROM (0000-1FFF), 32 KB RAM (2000-9FFF), 8 KB I/O (E000-FFFF).

A15 A14 A13 A12  →  Decoder  →  Chip Selects
 0   0   0   0   →     0     →  ROM (0000-1FFF)
 0   0   1   x   →     1     →  RAM (2000-5FFF) -- wait, 32KB = 8000H bytes

32 KB RAM = 8000H bytes. 2000H to 9FFFH. 8 KB ROM = 2000H bytes. 0000H to 1FFFH. 8 KB I/O = 2000H bytes. E000H to FFFFH.

Decoder logic:

  • ROM: A15=0, A14=0, A13=0 → CS_ROM = A15'·A14'·A13'
  • RAM: A15=0, (A14=1 or A13=1) but not E000-FFFF... better use full decode.

74LS138 (3-to-8 decoder) example:

  • Inputs: A15, A14, A13 → 8 outputs (each 8 KB block)
  • Y0: 0000-1FFF (ROM)
  • Y1: 2000-3FFF (RAM)
  • Y2: 4000-5FFF (RAM)
  • Y3: 6000-7FFF (RAM)
  • Y4: 8000-9FFF (RAM)
  • Y5: A000-BFFF (unused)
  • Y6: C000-DFFF (unused)
  • Y7: E000-FFFF (I/O)

Memory address map diagram

FFFF ┌─────────────┐
     │   I/O       │  8 KB (E000-FFFF)
E000 ├─────────────┤
     │   Unused    │  16 KB (A000-DFFF)
A000 ├─────────────┤
     │   RAM       │  8 KB (8000-9FFF)
8000 ├─────────────┤
     │   RAM       │  8 KB (6000-7FFF)
6000 ├─────────────┤
     │   RAM       │  8 KB (4000-5FFF)
4000 ├─────────────┤
     │   RAM       │  8 KB (2000-3FFF)
2000 ├─────────────┤
     │   ROM       │  8 KB (0000-1FFF)
0000 └─────────────┘

8.5 Secondary Memory

Magnetic Disk (HDD)

Structure:

  • Platters: Rigid disks coated with magnetic material (both sides used).
  • Spindle: Rotates platters (5400-15000 RPM).
  • Read/Write heads: One per surface, on actuator arm.
  • Actuator: Moves heads radially (voice coil motor).

Organization:

  • Track: Concentric circle on one surface.
  • Cylinder: Set of tracks at same radius on all surfaces.
  • Sector: Fixed-size block (512 bytes traditional, 4 KB advanced format).
  • Address: (Cylinder, Head, Sector) — CHS addressing.

Access time:

  • Seek time: Move head to cylinder (4-10 ms average).
  • Rotational latency: Wait for sector (½ rotation ≈ 4 ms at 7200 RPM).
  • Transfer time: Read/write data (depends on density, ~100-200 MB/s).

Cache Memory

Purpose: Bridge speed gap between CPU and main memory.

Mapping functions:

  • Direct mapped: Block → specific cache line (index = block mod cache_lines). Simple, conflict misses.
  • Fully associative: Block → any line. Complex search (CAM), no conflict misses.
  • Set associative: Compromise. Block → specific set, any way within set. 2-way, 4-way, 8-way common.

Cache line (block): Unit of transfer (32-128 bytes). Contains data + tag + valid bit.

Write policies:

  • Write-through: Write to cache and memory simultaneously. Safe, slow.
  • Write-back: Write to cache only; write to memory on eviction (dirty bit). Fast, complex.

Replacement policies (associative): LRU (Least Recently Used), Random, FIFO, Pseudo-LRU.

Performance metric:

  • Hit rate: Hits / (Hits + Misses)
  • AMAT (Average Memory Access Time): Hit_time + Miss_rate × Miss_penalty

Example: 4-way set associative, 32 KB cache, 64-byte lines.

  • Lines = 32 KB / 64 B = 512 lines
  • Sets = 512 / 4 = 128 sets (7 index bits)
  • Tag = Address bits - index - offset (offset = 6 bits for 64 B)

Key terms

I/O interface · isolated I/O · memory-mapped I/O · interrupt · polling · ISR · vectored · non-vectored · maskable · DMA · DMAC · HOLD · HLDA · cycle stealing · burst mode · memory hierarchy · locality · SRAM · DRAM · RAS · CAS · DDR · ROM · PROM · EPROM · EEPROM · Flash · address decoding · cache · direct mapped · set associative · write-through · write-back · LRU · hit rate · AMAT · magnetic disk · cylinder · sector · seek time · rotational latency

Revision points

  • Isolated I/O: separate address space, IN/OUT instructions. Memory-mapped: same space, LOAD/STORE.
  • Interrupt: device-initiated, CPU runs ISR. Priority: TRAP > RST 7.5 > 6.5 > 5.5 > INTR.
  • DMA: DMAC transfers without CPU. Modes: burst, cycle stealing, demand.
  • Memory hierarchy: registers → L1 → L2 → L3 → RAM → SSD/HDD.
  • DRAM: capacitor + transistor, needs refresh. SRAM: 6T, fast, cache.
  • Address decoding: high bits select chip (e.g., 74LS138).
  • Cache: direct / set-assoc / fully-assoc. Write-through vs write-back.
  • Disk: seek + rotational latency + transfer. SSD: no moving parts, faster.

Practice questions

  1. Draw the memory address map for a system with 16 KB ROM at 0000H, 48 KB RAM at 4000H, and 8 KB I/O at E000H. Show decoder logic.
  2. Explain the difference between cycle stealing and burst mode DMA.
  3. A disk has 7200 RPM, average seek 8 ms, 512-byte sectors, 200 MB/s transfer. Calculate average access time for 1 sector.
  4. Compare direct-mapped and 4-way set-associative cache for conflict misses.
  5. Why does DRAM need refresh? How often?

Unit 9: Pipelining

Teaching hours: 4

Topics in outline order

  1. Concept of pipelining and Flynn's classification, pipelining example with speed-up ratio
  2. Arithmetic pipeline, pipeline for floating-point addition and subtraction
  3. Instruction pipeline: four-segment instruction pipeline
  4. Data dependency, handling of branch instruction, pipeline hazards and their solutions

9.1 Concept of Pipelining

Pipelining: Overlapping execution of multiple instructions by dividing processing into stages. Each stage completes a part of an instruction per clock cycle.

Analogy: Laundry pipeline — wash, dry, fold, store. 4 loads take 4× time sequentially; with pipeline, ~1 load per cycle after fill.

Speedup:

  • Sequential: k stages, n instructions → n × k cycles
  • Pipelined: k stages, n instructions → k + (n - 1) cycles
  • Speedup ratio: (n × k) / (k + n - 1) → k as n → ∞

Example: 4-stage pipeline, 100 instructions

  • Sequential: 100 × 4 = 400 cycles
  • Pipelined: 4 + 99 = 103 cycles
  • Speedup: 400/103 ≈ 3.88× (ideal 4×)

Ideal conditions: No hazards, constant stage time, continuous instruction stream.

Flynn's Classification (Computer Architecture Taxonomy)

Class Instruction Streams Data Streams Description
SISD Single Single Sequential (von Neumann)
SIMD Single Multiple Vector/array processor (GPU)
MISD Multiple Single Theoretical (fault tolerance)
MIMD Multiple Multiple Multiprocessor, multicore

Swipe to see all columns

Pipelining is a technique within SISD (and used in SIMD/MIMD cores) to increase instruction throughput.


9.2 Arithmetic Pipeline

Arithmetic pipeline: Pipelines floating-point or complex arithmetic operations (add, multiply, divide).

Floating-point addition/subtraction pipeline

Steps for FP add/sub (A × 2^a ± B × 2^b):

1. Compare exponents:  a - b
2. Align mantissas:    Shift smaller mantissa right by |a-b|
3. Add/Subtract:       Mantissa arithmetic
4. Normalize:          Shift result to 1.xxxx form, adjust exponent
5. Round:              Round to precision (guard, round, sticky bits)
6. Check overflow/underflow

Pipeline stages (4-6 stages typical):

Stage Operation Time
S1 Exponent compare, choose larger 1 cycle
S2 Mantissa alignment (barrel shifter) 1 cycle
S3 Mantissa add/sub (FP adder) 1 cycle
S4 Normalize (leading zero detector + shifter) 1 cycle
S5 Round, pack result 1 cycle

Example: Add 1.101×2^3 + 1.011×2^1

  1. Exponents: 3 vs 1 → diff = 2
  2. Align: 1.011×2^1 = 0.01011×2^3 (shift right 2)
  3. Add: 1.101 + 0.01011 = 1.11111
  4. Normalize: 1.11111 already normalized
  5. Round: 1.11111 → 1.11111 (exact)
  6. Result: 1.11111×2^3

9.3 Instruction Pipeline

Instruction pipeline: Overlaps fetch, decode, execute, memory, writeback of successive instructions.

Four-segment instruction pipeline

Classic simple pipeline (e.g., early RISC):

Stage Name Operation
IF Instruction Fetch PC → memory → instruction register; PC ← PC + 4
ID Instruction Decode Decode opcode, read registers, sign-extend immediate
EX Execute ALU operation (add, logic, branch compare)
WB Write Back Write ALU result to register file

Memory access often combined with EX (for register ops) or separate MEM stage (5-stage).

Pipeline timing diagram (4-stage, 5 instructions)

Cycle:    1  2  3  4  5  6  7  8
I1:      IF ID EX WB
I2:         IF ID EX WB
I3:            IF ID EX WB
I4:               IF ID EX WB
I5:                  IF ID EX WB
  • Fill time: k cycles (4) for first instruction to complete.
  • Steady state: 1 instruction completes per cycle.
  • Drain time: k-1 cycles after last instruction enters.

9.4 Pipeline Hazards and Solutions

Types of hazards

Hazard Cause Example Solution
Structural Resource conflict (two instructions need same unit) IF and MEM both need memory Separate I-cache/D-cache; duplicate units
Data (RAW) Read After Write — instruction needs result not ready ADD R1,R2,R3 / SUB R4,R1,R5 Forwarding (bypassing), stall
Data (WAR) Write After Read — anti-dependency Rare in in-order; SUB R1,R2,R3 / ADD R2,R4,R5 Register renaming (out-of-order)
Data (WAW) Write After Write — output dependency Rare in in-order; ADD R1,R2,R3 / SUB R1,R4,R5 Register renaming
Control (Branch) Next instruction unknown until branch resolved BEQ R1,R2,target Prediction, delayed branch, speculation

Swipe to see all columns

Data hazard: RAW (Read After Write)

Example:

I1: ADD R1, R2, R3    ; R1 = R2 + R3
I2: SUB R4, R1, R5    ; R4 = R1 - R5  (needs R1 from I1)

Pipeline without forwarding:

I1: IF ID EX WB
I2:    IF ID  --stall-- EX WB   (2 cycles stall)

Forwarding (Bypassing): Route ALU result directly from EX/MEM/WB to next instruction's ID/EX.

  • EX→EX forward: I1 EX result → I2 EX input (most common)
  • MEM→EX forward: I1 MEM result → I2 EX input
  • WB→EX forward: I1 WB result → I2 EX input

With forwarding:

I1: IF ID EX WB
I2:    IF ID EX WB   (no stall if ALU→ALU forward)

Load-use hazard (requires stall even with forwarding):

I1: LOAD R1, 0(R2)  ; R1 = M[R2]
I2: ADD R3, R1, R4  ; Needs R1

LOAD data available at end of MEM stage. I2 needs it at EX. 1 cycle stall mandatory.

Control hazard: Branch instructions

Problem: Pipeline fetches next sequential instruction, but branch may go elsewhere.

Solutions:

  1. Stall until resolved: Freeze pipeline until branch condition known (simple, slow).

    • Branch resolved in ID (compare registers) → 1 cycle stall.
    • Branch resolved in EX → 2 cycle stall.
  2. Static prediction: Always predict not-taken (fetch sequential) or taken (fetch target).

    • Predict not taken: Continue sequential. If taken, flush pipeline (penalty = pipeline depth).
    • Predict taken: Fetch target (needs target address early — ID stage).
  3. Delayed branch (MIPS): Instruction after branch (delay slot) always executes. Compiler fills with useful instruction or NOP.

  4. Dynamic prediction (modern):

    • Branch history table (BHT): 1-2 bits per branch, tracks taken/not-taken.
    • Two-level predictor: Global history + local history.
    • Branch target buffer (BTB): Caches target address for predicted-taken branches.
    • Return address stack (RAS): Predicts function returns.
  5. Speculative execution: Execute predicted path, commit if correct, flush if wrong.

Structural hazard solutions

  • Separate instruction and data caches (Harvard architecture for L1).
  • Multi-port register file (2 read, 1 write for classic RISC).
  • Duplicate functional units (multiple ALUs, load/store units).

Key terms

Pipelining · speedup · Flynn's taxonomy · SISD · SIMD · MIMD · arithmetic pipeline · floating-point pipeline · exponent alignment · normalization · instruction pipeline · IF · ID · EX · MEM · WB · structural hazard · data hazard · RAW · WAR · WAW · control hazard · forwarding · bypassing · load-use hazard · branch prediction · static · dynamic · BHT · BTB · speculative execution · delayed branch · pipeline stall · flush · fill · drain · steady state

Revision points

  • Speedup = (n×k)/(k+n-1) → k for large n.
  • 4-stage pipeline: IF, ID, EX, WB (or 5-stage with MEM).
  • Hazards: Structural (resource), Data (RAW/WAR/WAW), Control (branch).
  • Forwarding solves most RAW; load-use needs 1 stall.
  • Branch: static (not-taken), delayed slot, dynamic (BHT, BTB), speculative.
  • FP pipeline: compare exp → align → add → normalize → round.

Practice questions

  1. Calculate speedup for 6-stage pipeline with 200 instructions. What is efficiency?
  2. Show pipeline timing for: ADD R1,R2,R3 / SUB R4,R1,R5 / AND R6,R1,R7 with forwarding.
  3. Explain load-use hazard. Why can't forwarding eliminate it completely?
  4. Compare static vs dynamic branch prediction. What is a branch target buffer?
  5. Design a 3-stage floating-point multiply pipeline (multiply mantissas, add exponents, normalize).

Exam Strategy

  • 8085 programming: Practice writing/tracing: array sum, max/min, search, sort (bubble), block move, multiplication/division subroutines.
  • Timing diagrams: Memorize opcode fetch (4T), memory read/write (3T), I/O read/write (3T). Show ALE, RD, WR, AD0-AD7, A8-A15.
  • 8086 segmentation: Physical = Segment×16 + Offset. Practice calculations.
  • Control unit: Know fetch micro-operations, difference between hardwired/microprogrammed, horizontal/vertical microinstruction.
  • RISC vs CISC: Table comparison. Modern x86 = CISC ISA + RISC micro-ops.
  • Booth algorithm: Step-by-step with (Q_i, Q_{i-1}) pairs. Arithmetic right shift preserves sign.
  • DMA: Cycle stealing vs burst. HOLD/HLDA handshake.
  • Memory: Address decoding with 74LS138. Cache mapping (direct, set-assoc). Write policies.
  • Pipelining: Speedup formula. Hazard types and solutions (forwarding, prediction, stalls).
  • Diagrams: Draw block diagrams (8085, 8086, pipeline, cache, DMA) with labels.

Comprehensive Practice Questions

  1. Write an 8085 program to sort 10 bytes at 3000H in ascending order.
  2. Draw the complete timing diagram for LDA 2050H showing all signals for 3 machine cycles.
  3. Calculate physical addresses: CS=1000H, IP=0020H; DS=2000H, SI=0010H; SS=3000H, SP=000AH.
  4. Write the symbolic microprogram for STA addr (store accumulator direct).
  5. Compare RISC and CISC in a table with 8 parameters.
  6. Multiply -6 × 5 using Booth's algorithm (5-bit). Show all steps.
  7. Explain cycle-stealing DMA with a timing diagram showing CPU and DMA bus usage.
  8. A system has 16 KB ROM at 0000H, 48 KB RAM at 4000H. Design address decoding using 74LS138.
  9. For a 4-way set-associative cache (32 KB, 64-byte lines), calculate tag/index/offset bits for 32-bit address.
  10. List the three pipeline hazard types. For each, give one example and one solution.
  11. Explain how dynamic branch prediction works with a 2-bit saturating counter.
  12. What is the difference between write-through and write-back cache? Which needs a dirty bit?