Nov 19, 2026·Pranesh Mahanta·21CSS201T — Computer Organization and Architecture
The functional units, buses, memory addressing and instruction machinery of a basic computer — sequencing, addressing modes, and a full case study of the 8086’s registers, segmentation and instruction groups.
Whatever its size or speed, every computer can be described by five functional units: the input unit, which enters data and programs; the memory unit, which stores both, keeping programs as binary instructions; the arithmetic and logic unit (ALU), which performs arithmetic and comparisons; the control unit, which fetches, decodes and sequences the instructions; and the output unit, which returns results. The ALU together with the control unit forms the central processing unit (CPU). The defining idea of the stored-program (von Neumann) machine is that instructions live in the same memory as data and are therefore as easy to change as data.
Unit
Role
Typical hardware
Input
Enters programs and data
Keyboard, disk, network port
Memory
Stores instructions and data
RAM, caches, ROM
ALU
Arithmetic, logic, comparisons
Adder, shifter, flag logic
Control
Fetch, decode, sequence
PC, IR, decoder, control signals
Output
Delivers results
Display, disk, network port
When instruction memory and data memory are separate (as in most microcontrollers), the organisation is called Harvard; when they share one memory and one bus, it is von Neumann. The 8086 studied later in this unit is a von Neumann machine with segmented addressing.
2Operational concepts: the instruction cycle
A program executes as an endless repetition of the instruction cycle: fetch the next instruction from memory at the address held in the program counter (PC), decode it in the instruction register (IR), execute the required data transfers and operations through the ALU and memory, then update the PC. Memory accesses for operands go through the memory address register (MAR) and memory data register (MDR), which isolate the CPU’s internal buses from the system bus. Executing a single instruction such as Add the contents of memory location X to register R1 therefore involves several distinct steps: fetch the instruction, fetch the operand X, add, and store the result.
Execution time = (number of instructions) × (average cycles per instruction) × (clock cycle time)
MIPS rate = instructions per second / 106
Worked problem · execution time and MIPS rate
A computer has a 500 MHz clock. A benchmark program contains 2 × 106 machine instructions, and on average each instruction takes 6 clock cycles to complete. Find (a) the time to execute the program and (b) the MIPS rate.
Clock cycle time: T = 1/f = 1/(500 × 106 Hz) = 2 ns. Time per instruction: 6 cycles × 2 ns = 12 ns. (a) Program time: 2 × 106 × 12 ns = 24 × 106 ns = 24 ms. (b) MIPS rate: 2 × 106 instructions / 0.024 s = 83.3 × 106 instructions/s ≈ 83.3 MIPS. Check: cycles executed = 2 × 106 × 6 = 12 × 106; at 500 MHz this takes 12 × 106/500 × 106 = 0.024 s. Consistent.
3Bus structures
A bus is a shared set of conductors that carries information between functional units. The simplest organisation is a single bus: one address bus, one data bus and one control bus link the CPU, memory and all I/O interfaces, so only one transfer can happen at a time. More performance is bought with multiple buses — a separate memory bus and I/O bus, or a high-speed front-side path plus a slower peripheral path — at the cost of extra interface hardware and arbitration. Because the bus is shared, an arbitration scheme decides which unit may drive it, and each attached unit needs tri-state outputs so it can disconnect from the wires.
Figure — a single-bus computer: PC, IR, MAR and MDR plus the general registers and ALU inside the CPU; memory and I/O interfaces hang off the shared bus.
Worked problem · bus bandwidth
A system bus transfers 32-bit data words and runs at 100 MHz, completing one data transfer per clock cycle. (a) What is the data bandwidth in MB/s (1 MB = 106 bytes)? (b) If a new protocol needs two cycles per transfer, what is the new bandwidth?
(a) 32 bits = 4 bytes per transfer. One transfer per cycle → 100 × 106 transfers/s.
Bandwidth = 4 B × 100 × 106 = 400 MB/s. (b) Two cycles per transfer halves the transfer rate to 50 × 106 transfers/s.
Bandwidth = 4 × 50 × 106 = 200 MB/s. Note: bandwidth always equals (bytes per transfer) × (transfers per second) — protocol overhead such as address setup and wait states is what separates the two answers.
4Memory addresses and operations
Memory is an array of cells, each identified by an address. A machine is byte-addressable if every 8-bit byte has its own address (the modern norm) or word-addressable if addresses name whole machine words. With 32-bit words in a byte-addressable machine, consecutive words sit at addresses 0, 4, 8 … and the n-bit address register selects 2n cells. The two elementary operations are Read (copy the contents of the addressed cell out, leaving it unchanged) and Write (overwrite the addressed cell). When a multi-byte value spans several addresses, its byte order distinguishes little-endian machines (least significant byte at the lowest address) from big-endian ones (most significant byte first).
Number of addressable cells = 2n for an n-bit address (n = 32 → 4 GiB; n = 20, as in the 8086, → 1 MB).
Worked problem · address space and word storage
A machine uses 32-bit byte addresses and has 32-bit machine words. (a) How many bytes can it address? (b) How many whole words? (c) If the 32-bit word 1234567816 is stored starting at byte address 1000 on a little-endian machine, which byte sits at address 1000?
(a) 232 bytes = 4,294,967,296 bytes = 4 GiB. (b) Each word covers 4 bytes, so words = 232/4 = 230 = 1,073,741,824 words. (c) Little-endian puts the least significant byte at the lowest address: byte A0... here the value is 1234567816, so its LSB is 7816. Address 1000 holds 7816, address 1001 holds 5616, address 1002 holds 3416 and address 1003 holds 1216. Check: reading the four bytes little-endian from 1000 gives 78 56 34 12 → value 1234567816. Correct.
A word access must use an address aligned to the word size (multiple of 4 here); unaligned access either traps or silently costs an extra memory cycle, which is why compilers pad structures to alignment boundaries.
5Assembly language
Machine instructions are binary patterns, unreadable to humans. Assembly language replaces each binary instruction with a mnemonic and symbolic names: ADD R1, R2 instead of an opcode bit field. The assembler translates the source into machine code; because instructions may reference labels defined later in the file, the assembler works in two passes — the first builds the symbol table of label addresses, the second emits code with the values resolved. Assembly also supports directives (instructions to the assembler itself, not the CPU), such as reserving storage or defining constants, and pseudo-instructions that the assembler expands into one or more real instructions.
LOOP: ADD (R1)+, R0 add the word pointed to by R1, advance the pointer
SUB #1, R2 one element fewer left to process
BR>0 LOOP repeat while the counter R2 is still positive
A three-statement loop that sums an array: symbolic labels and a conditional branch replace the binary jump offsets a programmer would otherwise compute by hand.
Assembly is specific to one processor family — there is no portable assembly language. Its modern uses are boot code, device drivers and performance-critical inner loops where the programmer must control every instruction.
6Instructions and instruction types
An instruction has two parts: an opcode specifying the operation and one or more operand fields specifying where the data lives. Instruction sets differ on format: fixed-length encodings (typical of RISC machines such as ARM) simplify decoding, while variable-length encodings (typical of CISC machines such as the 8086, with 1- to 6-byte instructions) improve code density. Most real programs draw on a surprisingly small set of instruction classes.
Class
Purpose
Examples
Data transfer
Move data between registers and memory
MOVE, LOAD, STORE, PUSH, POP
Arithmetic
Compute numeric results
ADD, SUB, MUL, DIV, INC, DEC
Logical
Bitwise manipulation and tests
AND, OR, XOR, NOT, SHIFT, ROTATE
Compare / status
Set condition flags without destroying operands
COMPARE (CMP), TEST
Control transfer
Change the program counter
JUMP, conditional BRANCH, CALL, RETURN
I/O
Exchange data with peripheral ports
IN, OUT
A zero-address (stack) machine names no operands at all — instructions implicitly operate on the stack top — while one-, two- and three-address formats trade instruction length against the number of explicit memory references the programmer must write.
7Instruction sequencing
Instructions execute in the order they appear in memory: after each fetch the processor advances the PC by the instruction’s length. Branches break this straight-line flow. An unconditional jump always loads a new address into the PC; a conditional branch does so only if a tested condition holds, usually a bit in the status flags set by an earlier compare or arithmetic instruction. Procedure calls save the return address (on the stack or in a link register) before jumping, and RETURN restores it. With PC-relative sequencing, the branch target is specified as a signed offset from the already-updated PC, so the whole program is position-independent.
Straight line: PC ← PC + instruction length.
PC-relative branch: target = PC (updated) + signed offset.
Call: push return address → jump; Return: PC ← popped address.
Conditional sequencing is what turns a fixed instruction stream into a program: the loop example of section 5 decrements a counter and branches back while the counter is positive, and every if-statement in a high-level language compiles to a compare plus a conditional branch.
Note the sign-extension detail: a negative offset moves backward (loops), a positive offset forward (skip-over code). Since the offset field has finite width, the reachable range around the PC is limited — long-distance jumps use absolute address forms.
8Addressing modes
An addressing mode is the rule by which an instruction derives its operand. The effective address (EA) is the final memory address (or register) actually used. Modes trade flexibility against encoding cost: immediate and register modes are fast but confined, while indexed and relative modes support arrays, records and relocatable code. The table below is the canonical set; the worked problem evaluates each mode numerically.
Mode
Meaning
Effective address
Immediate
Operand is in the instruction itself
— (no memory access)
Direct (absolute)
Address field holds the address
EA = A
Indirect
Address field points to a pointer
EA = M[A]
Register
Operand is in a register
— (no memory access)
Register indirect
Register holds the address
EA = contents of R
Indexed
Base address + index register
EA = A + (XR)
Relative
Offset from the program counter
EA = PC + offset
Autoincrement / autodecrement
Use register, then step it by the word size
EA = (R), then R ← R ± word size
Worked problem · evaluating addressing modes
In a word-addressable machine: PC = 250, R1 = 400, index register XR = 50. Memory contents: M[100] = 500, M[300] = 900, M[400] = 600, M[450] = 350, M[500] = 700, M[600] = 800. Determine the operand fetched for each instruction: (a) immediate #50; (b) direct 100; (c) indirect (100); (d) register R1; (e) register indirect (R1); (f) indexed 400(XR); (g) relative +50; (h) autoincrement (R1)+.
(a) Immediate: the operand is the constant in the instruction itself → 50. No memory access. (b) Direct: EA = 100 → operand = M[100] = 500. (c) Indirect: first read M[100] = 500 as a pointer, then EA = 500 → operand = M[500] = 700. (Two memory accesses.) (d) Register: the operand is the register content itself → 400. (e) Register indirect: EA = (R1) = 400 → operand = M[400] = 600. (f) Indexed: EA = 400 + 50 = 450 → operand = M[450] = 350. (g) Relative: EA = PC + 50 = 250 + 50 = 300 → operand = M[300] = 900. (h) Autoincrement: EA = (R1) = 400 → operand = M[400] = 600; afterwards R1 is stepped to 401 (next word).
Examiners count memory accesses: direct needs one, indirect needs two, immediate and register need none. Saying so explicitly in the answer is usually worth marks.
9Case study 8086: the programmer’s registers
The Intel 8086 (1978, 16-bit, 29,000 transistors) exposes fourteen 16-bit registers. Four general data registers AX, BX, CX and DX each split into high and low halves (AH/AL, BH/BL, CH/CL, DH/DL), so the same register serves 16-bit or 8-bit operations; each also has a dedicated role — AX is the accumulator for arithmetic, BX the base for addressing, CX the implicit count for loops and string operations, DX the data register for I/O and multiply/divide extensions. Four pointer and index registers follow: SP (stack pointer), BP (stack frame base), SI and DI (source and destination index for string instructions). Four segment registers CS, DS, SS and ES hold segment bases, IP is the 16-bit instruction pointer, and FLAGS carries CF, ZF, SF, PF, AF and OF plus control flags IF, DF and TF.
Group
Registers
Special roles
General data
AX, BX, CX, DX
AX accumulator; BX base; CX count; DX I/O and MUL/DX-AX
Pointers / index
SP, BP, SI, DI
SP+BP with SS; SI/DI with DS for string ops
Segment
CS, DS, SS, ES
Code, data, stack, extra data segment bases
Status / control
IP, FLAGS
IP = PC of the current segment; FLAGS condition and control bits
Register conventions are enforced by the instruction set, not by choice: LOOP always uses CX, string instructions always use SI/DI, and MUL leaves a 32-bit product in DX:AX. Code written against these conventions reads correctly everywhere.
10Case study 8086: memory segmentation
The 8086 has 20 address pins but only 16-bit registers, so it forms 20-bit physical addresses out of two 16-bit pieces: every memory reference names a segment (from a segment register) and an offset. The physical address is the segment base shifted left four bits (multiplied by 16, i.e. ×10H — a paragraph) plus the offset. Each segment spans 64 KB, and because starts are only 16 bytes apart, segments overlap heavily — 216 = 65,536 distinct starting paragraphs tile the 1 MB space.
Figure — 8086 address formation: the segment base is shifted left four bits and the offset is added, producing the 20-bit physical address.
Worked problem · computing physical addresses
(a) Given CS = 2400H and IP = 1234H, find the physical address of the next instruction. (b) Given DS = 4A00H, BX = 0200H and SI = 0010H, find the physical address read by MOV AX, [BX+SI].
(a) PA = CS × 10H + IP = 24000H + 1234H = 25234H. (b) Offset = BX + SI = 0200H + 0010H = 0210H; segment = DS.
PA = 4A000H + 0210H = 4A210H. Check: both results fit in 20 bits (below 100000H), as every 8086 address must.
Worked problem · memory capacity of the 8086
The 8086 has 20 address lines. (a) How much memory can it address? (b) What is the largest single segment? (c) How many distinct segment-start addresses exist? (d) How many non-overlapping full-size segments fit in the address space?
(a) 220 bytes = 1,048,576 bytes = 1 MB. (b) The offset is 16 bits → largest segment = 216 = 64 KB. (c) Segment starts are multiples of 16 (paragraphs); the base field is 16 bits → 216 = 65,536 distinct starting addresses. (d) 1 MB / 64 KB = 1,048,576 / 65,536 = 16 non-overlapping segments. Note: since starts occur every 16 bytes, adjacent segments overlap by 65,520 bytes — segmentation gives a 64 KB window slid in 16-byte steps anywhere in the megabyte.
Worked problem · stack push and pop
In an 8086 system SS = 4000H and SP = 2000H. The instruction PUSH AX executes with AX = 50A0H. (a) What is the new value of SP? (b) At which physical addresses are the two bytes stored, and what does each hold? (c) What does POP AX do afterwards?
(a) PUSH first decrements SP by 2 (the stack grows downward): SP = 2000H − 2 = 1FFEH. (b) The word is stored at PA = SS × 10H + SP = 40000H + 1FFEH = 41FFEH. Little-endian layout: the low byte A0H at 41FFEH and the high byte 50H at 41FFFH. (c) POP AX reverses it: read the word at 41FFEH (50A0H) into AX, then increment SP by 2, restoring SP = 2000H. Check: the stack is LIFO — a second PUSH BX would place BX at SP = 1FFCH, PA = 41FFCH, above AX in memory.
11Addressing modes of the 8086
The 8086 refines the generic modes into memory forms built from a base register (BX or BP), an index register (SI or DI) and an optional 8- or 16-bit displacement: [BX+SI+disp] is the fullest memory form. The segment used is by default DS for BX/SI/DI references but SS for BP references — an important detail, since BP normally addresses stack frames. Immediate, register and direct modes work as in any machine; string instructions implicitly use SI and DI, and ports are addressed by immediate (8-bit) or DX (16-bit) port numbers.
Mode
Form
Offset computation
Default segment
Immediate
MOV AX, 1234H
— operand in instruction
—
Register
MOV AX, BX
— operand in register
—
Direct
MOV AX, [1234H]
1234H
DS
Register indirect
MOV AX, [BX]
(BX)
DS
Based
MOV AX, [BX+06H]
(BX) + 6
DS (SS if BP)
Indexed
MOV AX, [SI+10H]
(SI) + 10H
DS
Based-indexed
MOV AX, [BX+SI]
(BX) + (SI)
DS
Based-indexed + disp
MOV AX, [BX+SI+08H]
(BX) + (SI) + 8
DS
Worked problem · identifying modes and computing addresses
Given DS = 3000H, SS = 4000H, BX = 0100H, SI = 0020H, DI = 0040H, BP = 0200H, identify the addressing mode of each instruction and compute the 20-bit physical address of any memory operand: (a) MOV AX, 1234H; (b) MOV AX, BX; (c) MOV AX, [1234H]; (d) MOV AX, [BX]; (e) MOV AX, [BX+06H]; (f) MOV AX, [BX+SI]; (g) MOV AX, [BX+SI+08H]; (h) MOV AX, [BP+DI].
(a) Immediate — no memory operand. (b) Register — no memory operand. (c) Direct. Offset = 1234H; PA = 30000H + 1234H = 31234H. (d) Register indirect. Offset = 0100H; PA = 30000H + 0100H = 30100H. (e) Based. Offset = 0100H + 06H = 0106H; PA = 30000H + 0106H = 30106H. (f) Based-indexed. Offset = 0100H + 0020H = 0120H; PA = 30000H + 0120H = 30120H. (g) Based-indexed with displacement. Offset = 0100H + 0020H + 08H = 0128H; PA = 30000H + 0128H = 30128H. (h) Based-indexed (BP forms) — default segment is SS, not DS. Offset = 0200H + 0040H = 0240H; PA = 40000H + 0240H = 40240H.
Part (h) is the classic trap: BP-based addressing defaults to the stack segment. Mentioning the default-segment rule explicitly is what distinguishes a complete answer.
12Instruction groups of the 8086
The 8086 instruction set (about 133 instruction types) is conventionally sorted into six groups. Data transfer moves operands without touching flags: MOV, PUSH, POP, XCHG, LEA, IN, OUT. Arithmetic operates on signed and unsigned data: ADD, ADC, SUB, SBB, INC, DEC, CMP, MUL/IMUL, DIV/IDIV. Logical covers bitwise and shift operations: AND, OR, XOR, NOT, TEST, SHL/SHR, SAR, ROL/ROR, RCL/RCR. String instructions process memory blocks with implicit SI/DI and optional REP prefixes: MOVS, CMPS, SCAS, LODS, STOS. Control transfer changes the program counter: JMP, the conditional family Jcc (JZ, JNZ, JC, JS, JG…), CALL, RET, LOOP, INT and IRET. Processor control manages the machine state: STC/CLC/CMC, STD/CLD, STI/CLI, HLT, NOP.
Group
Flags affected
Representative instructions
Data transfer
none
MOV, PUSH, POP, XCHG, LEA, IN, OUT
Arithmetic
CF, ZF, SF, OF, PF, AF
ADD, SUB, CMP, MUL, DIV, INC, DEC
Logical / shift
CF, ZF, SF, PF (OF for shifts)
AND, OR, XOR, NOT, SHL, SHR, ROL
String
CMPS/SCAS set flags; others none
MOVS, CMPS, SCAS, LODS, STOS (± REP)
Control transfer
none (they test flags)
JMP, Jcc, CALL, RET, LOOP, INT, IRET
Processor control
individual flag bits
STC, CLC, STD, STI, HLT, NOP
CMP is simply a SUB that discards the result but keeps the flags — every conditional branch in real code is fed by a CMP or an arithmetic instruction. LEA is likewise a “MOV without memory access”: it computes the offset itself, so it doubles as an add-and-multiply-by-scale arithmetic trick.
13Execution walkthrough: a small 8086 program
Tying the unit together, follow a two-instruction fragment through fetch, decode, execute and flag update. The program adds the constant 27H to the low byte 15H already in AL. Each instruction is fetched from CS:IP, decoded into opcode plus operands, executed through the ALU, and the FLAGS register is rewritten by the arithmetic.
Starting with AL = 00H and FLAGS clear, the following program runs: MOV AL, 15H; then ADD AL, 27H. Give the value of AL after each instruction and the state of CF, AF, ZF, SF and PF after the ADD. (PF = 1 when the low byte of the result has an even number of 1s; AF is the carry out of bit 3.)
Instruction 1 — MOV AL, 15H: fetch (CS:IP), decode as immediate-to-register, execute: AL ← 15H. MOV affects no flags. Instruction 2 — ADD AL, 27H: fetch, decode as register-plus-immediate, execute in the ALU:
15H = 0001 0101 and 27H = 0010 0111; sum = 0011 1100 = 3CH → AL = 3CH. Flag results: bit 7 carry? no → CF = 0. Low nibble 5H + 7H = 0CH — no carry out of bit 3 → AF = 0. Result nonzero → ZF = 0. Bit 7 of 3CH is 0 → SF = 0. 3CH = 0011 1100 has four 1s (even) → PF = 1. Check: 15H + 27H = 21 + 39 = 60 = 3CH. Correct.
Sequence the concepts backwards and the unit closes its loop: the fetch used CS:IP (segmentation), the operands used immediate and register addressing (modes), the ALU did 8-bit binary addition (number systems), and the flags now steer whatever conditional branch comes next (sequencing).