Instruction formats, addressing & bus organization
An instruction names an operation and where its operands are; addressing modes turn its address field into an effective address. Address, data and control buses carry those accesses, and their width, timing and arbitration decide how much memory a system reaches and how fast.
Medium 55 minSyllabus: “Processor addressing and bus organization”
Mark as
The idea in one minute
An instruction is like a delivery note. The opcode says what to do (“add”), and the address field says where the parcel is. Sometimes the note carries the parcel itself (immediate), sometimes a locker number (direct), sometimes the number of a locker holding another locker number (indirect). The bus is the road between CPU and memory: address lanes say which house, data lanes carry the parcel, and control lanes are the traffic signals. When several drivers want the road at once, an arbiter decides who goes.
Key points — the night-before list
Instruction = opcode + mode + address/register fields; N operations need ⌈log₂N⌉ opcode bits; 3-, 2-, 1- and 0-address formats trade instruction length against instruction count.
0-address instructions use a stack (PUSH, POP, ADD); 1-address use an implied accumulator; RISC load–store keeps every ALU operand in registers.
EA rules: direct A; indirect M[A]; register indirect R; relative PC + A; indexed XR + A; base BR + A. Immediate operand is inside the instruction.
Autoincrement: EA = R, then R ← R + d. Autodecrement: R ← R − d first, then EA = R. Relative mode uses the PC after fetch.
Address bus is unidirectional (CPU → memory/I/O); data bus is bidirectional; n address lines reach 2ⁿ locations; data-bus width = bits per transfer.
01What an instruction must say: formats and fields
Every machine instruction answers three questions: what operation (the opcode), where the operands are (address or register fields) and how to interpret those fields (the mode). The layout of these fields within the instruction word is the instruction format.
Field widths follow from simple counting. N different operations need at least ⌈log₂N⌉ opcode bits; a field naming one of R registers needs log₂R bits; a direct address into 2ᵐ words needs m bits. Mano's basic computer packs 1 indirect bit + 3 opcode bits + 12 address bits (for 4096 words) into one 16-bit word.
opcode bits ≥ ⌈log₂(number of operations)⌉
register field = log₂(number of registers)
address field = log₂(number of addressable words)
instruction size = opcode + mode + register fields + address fields
Counting bits in a format
Formats also depend on where the CPU keeps its operands. Mano names three CPU organisations, and real processors mix them:
Organisation
Operands live in
Typical instruction
Single accumulator
AC (implied) and memory
ADD X (AC ← AC + M[X])
General register
Processor registers R0…Rn and memory
ADD R1, R2, R3 (R1 ← R2 + R3)
Stack
Top of a push-down stack
ADD (pop two items, push their sum)
Tip
More addresses per instruction means fewer instructions per program but longer instructions; fewer addresses means shorter instructions but more of them. Every format is a trade-off between instruction length and instruction count.
02Three-, two-, one- and zero-address instructions
The classic way to compare formats is to compute X = (A + B) × (C + D), where A, B, C, D and X are memory words. ADD, MUL, MOV, LOAD and STORE are generic mnemonics; R1–R4 are registers, T is a temporary memory word and TOS means top of stack.
8086 assemblyThree-address and two-address forms
; three-address: two sources and a destination in every instruction
ADD R1, A, B ; R1 ← M[A] + M[B]
ADD R2, C, D ; R2 ← M[C] + M[D]
MUL X, R1, R2 ; M[X] ← R1 × R2; two-address: the first operand is also the destination
MOV R1, A ; R1 ← M[A]
ADD R1, B ; R1 ← R1 + M[B]
MOV R2, C ; R2 ← M[C]
ADD R2, D ; R2 ← R2 + M[D]
MUL R1, R2 ; R1 ← R1 × R2
MOV X, R1 ; M[X] ← R1
8086 assemblyOne-address (accumulator) and zero-address (stack) forms
; one-address: AC is the implied second operand and destination
LOAD A ; AC ← M[A]
ADD B ; AC ← AC + M[B]
STORE T ; M[T] ← AC (save A + B)
LOAD C ; AC ← M[C]
ADD D ; AC ← AC + M[D]
MUL T ; AC ← AC × M[T]
STORE X ; M[X] ← AC; zero-address: operands are implied at the top of the stack
PUSH A ; TOS ← A
PUSH B ; TOS ← B
ADD ; TOS ← A + B
PUSH C ; TOS ← C
PUSH D ; TOS ← D
ADD ; TOS ← C + D
MUL ; TOS ← (A + B) × (C + D)
POP X ; M[X] ← TOS
8086 assemblyLoad–store (RISC): only LOAD and STORE touch memory
Simple fixed-length instructions; ALU works on registers only
Watch out
Instruction count and memory references are different measures, and both exclude instruction fetches here. If the stack lives in memory rather than in registers, every PUSH, POP and stack ADD also touches memory. For non-commutative stack operations (SUB, DIV) the usual convention is second item op top item.
03Addressing modes: from address field to effective address
The effective address (EA) is the actual memory address of the operand, computed from the instruction's address field and possibly a register. Addressing modes are the rules for that calculation. They give programmers constants, pointers, arrays and relocatable code without a separate instruction for each case.
Mode
How the operand is found
Effective address
Typical use
Implied
Operand is implicit in the opcode
—
CLA, CMA, stack ADD
Immediate
Operand is inside the instruction
— (operand = address field)
Constants: MOV R1, #25
Register
Operand is in a register
— (operand = R)
Fast temporaries
Register indirect
Register holds the operand's address
EA = R
Pointers
Autoincrement
Register indirect, then the register steps up
EA = R, then R ← R + d
Walking an array, popping a stack
Autodecrement
Register steps down first, then is used
R ← R − d, then EA = R
Pushing onto a stack, walking backwards
Direct (absolute)
Address field is the operand's address
EA = A
Global and static variables
Indirect
Address field points to a word holding the EA
EA = M[A]
Pointers in memory, jump tables
Relative
Offset added to the program counter
EA = PC + A
Branches, position-independent code
Indexed
Address field plus index register
EA = XR + A
Arrays: A = array start, XR = element index
Base register
Base register plus displacement
EA = BR + A
Relocating programs and data segments
Here A is the instruction's address field, d is the operand size (1 for word-addressed memory, 2 or 4 for bytes), and PC is the value after the instruction has been fetched. Relative, indexed and base-register modes together form displacement addressing: the same adder (register + constant), with different roles for the two parts.
PSC favourite
Spot the mode from the syntax: MOV AX, 1562H is immediate, MOV AX, [1562H] is direct, MOV AX, [BX] is register indirect, MOV AX, [SI + 10H] is indexed, and JNZ LOOP with an 8-bit offset is relative. Direct, indirect and register addressing are all genuine addressing modes — a past paper listed them as statements and the answer was “all of these”. (8086 details are in the 8086 topic.)
Watch out
Indirect addressing costs an extra memory access to read the EA; register indirect does not, because the address is already in a register. That speed difference is why register indirect is far more common in practice.
04A worked effective-address table
Suppose a two-word “load AC” instruction sits at addresses 200 and 201, with the address field (500) in the second word. After fetching it, PC = 202. Register R1 = 400 and index register XR = 100. Memory holds M[399] = 175, M[400] = 640, M[500] = 820, M[600] = 930, M[702] = 315 and M[820] = 260. The mode field alone decides what ends up in AC:
Mode
Effective address
Operand loaded into AC
Immediate
201 (the operand is the instruction's second word)
500
Direct
500
820
Indirect
M[500] = 820
260
Relative
PC + 500 = 202 + 500 = 702
315
Indexed
XR + 500 = 100 + 500 = 600
930
Register
— (the operand is R1 itself)
400
Register indirect
R1 = 400
640
Autoincrement
400, then R1 ← 401
640
Autodecrement
R1 ← 399, then EA = 399
175
The same address-field bits yield eight different operands. With a base register BR = 100 in place of XR the arithmetic would match the indexed row (EA = 600) — indexed and base addressing differ only in which part holds the large fixed value.
How to solve any EA question
Find PC after fetch
Add the instruction's length to its starting address; relative mode uses this value, not the instruction's own address.
Apply the mode's formula
Direct uses A; indirect reads M[A]; register modes use the register; displacement modes add a register to A.
Read the operand
Except in immediate and register modes, the operand is M[EA].
Apply side effects
Autoincrement and autodecrement change the register; note whether the change happens after or before the access.
05Stack organisation
A stack is a last-in, first-out (LIFO) store with a stack pointer (SP) holding the address of the top item. Only two operations are allowed: PUSH inserts at the top and POP removes from the top. Stacks make zero-address instructions possible and hold subroutine return addresses, interrupt state and partial results of expressions.
Mano describes a register stack of 64 words with a 6-bit SP, a data register DR and two flags, FULL and EMTY. Because SP has only 6 bits it wraps from 63 to 0, so the first item goes to address 1 and the 64th lands at address 0.
TextMano's register stack (SP points to the top item)
PUSH: SP ← SP + 1
M[SP] ← DR
if (SP = 0) then (FULL ← 1)
EMTY ← 0
POP: DR ← M[SP]
SP ← SP − 1
if (SP = 0) then (EMTY ← 1)
FULL ← 0
A memory stack occupies part of main memory and usually grows toward lower addresses: PUSH does SP ← SP − 1 then M[SP] ← DR; POP does DR ← M[SP] then SP ← SP + 1. The 8086 works this way, moving SP by 2 per word. Pushing onto a full stack is overflow and popping an empty one is underflow; limit registers or the FULL/EMTY flags catch both.
Stacks evaluate expressions in reverse Polish notation (RPN) — postfix, with each operator after its operands (Polish notation is due to Jan Łukasiewicz). (A + B) × (C + D) becomes A B + C D + ×. Scan left to right: push each operand; on an operator, pop two items, apply it and push the result. With A = 3, B = 4, C = 5, D = 6:
Symbol read
Action
Stack (bottom → top)
3
push
3
4
push
3, 4
+
pop 4 and 3, push 7
7
5
push
7, 5
6
push
7, 5, 6
+
pop 6 and 5, push 11
7, 11
×
pop 11 and 7, push 77
77
Watch out
Stack conventions differ between books: Mano's register stack increments SP before a push while his memory stack decrements it, and some texts let SP point to the next free slot instead of the top item. In a numerical, follow the convention the question states.
06Bus structure: address, data and control lines
A bus is a shared set of wires carrying signals between components. The system bus that joins CPU, memory and I/O has three groups of lines:
Bus
Carries
Direction
Its width decides
Address bus
The location being accessed (memory word or I/O port)
Unidirectional: CPU (bus master) → memory and I/O
Address space: n lines → 2ⁿ locations
Data bus
The data or instruction being transferred
Bidirectional
Bits moved per transfer: 32 lines → 32 bits in parallel
Control bus
Commands and timing: MEMR, MEMW, IOR, IOW, clock, reset, interrupt request/acknowledge, bus request/grant, ready
Each line one-way, but signals flow both ways overall
Which operations and handshakes are possible
Address lines
Locations
Example
16
2¹⁶ = 65,536 (64 K)
8085
20
2²⁰ = 1,048,576 (1 M)
8086 — 1 MB
24
2²⁴ = 16,777,216 (16 M)
80286
32
2³² ≈ 4.29 × 10⁹ (4 G)
80386 and other 32-bit CPUs
Going the other way, a memory of 32K × 16 holds 32K = 2¹⁵ words of 16 bits, so it needs 15 address lines and 16 data lines — a past-paper question. Remember that n address lines give 2ⁿ addressable units: bytes on a byte-addressable machine, words on a word-addressable one.
Inside the CPU, Hamacher contrasts single-bus, two-bus and three-bus organisations. With one internal bus only one transfer happens per clock, so an ADD needs temporary registers (Y, Z) and several steps; with three buses both operands and the result move in the same clock, at the cost of more wiring and more register ports.
Single shared system bus
Simple and cheap; easy to add devices
Only one transfer at a time — becomes a bottleneck
Long, heavily loaded lines slow the signals
Fast and slow devices share one timing
Multiple-bus hierarchy
Local CPU–cache bus, memory bus, high-speed bus, expansion (I/O) bus
Bridges keep slow I/O traffic off the CPU–memory path
Several transfers proceed in parallel; higher total bandwidth
More complex and costly (e.g. PCI or PCIe with bridges)
Bandwidth = (bus width in bytes) × (clock rate) ÷ (clock cycles per transfer)
64-bit bus, 100 MHz, 1 cycle per transfer → 8 B × 100 × 10⁶ /s = 800 MB/s
same bus, 2 cycles per transfer → 400 MB/s
Bus bandwidth
07Synchronous and asynchronous bus timing
A bus master (CPU, DMA controller) starts a transfer and a slave (memory, I/O port) responds. The bus timing protocol fixes how both sides know when the address, command and data lines are valid.
Synchronous bus
A common clock line; every event happens on a clock edge
Fixed number of cycles per transfer (address, access, data)
Simple, fast control logic
Must be timed for the slowest device, or add wait states
Clock skew limits the bus length
Asynchronous bus
No common clock; uses handshake signals
MSYN/SSYN (master-ready/slave-ready), or strobe and acknowledge
Each transfer takes as long as the devices need
Mixes fast and slow devices freely
More control logic and some handshake overhead per transfer
In a synchronous read, the master puts the address and read command on the bus at the start of cycle 1, the slave decodes and accesses the data during the following cycles, and the master samples the data lines on a fixed later clock edge. Many processors add a READY (wait) line so a slow slave can stretch the cycle by inserting wait states — a semi-synchronous scheme the 8086 uses.
In an asynchronous read, the master places the address and command, waits a short skew time and raises MSYN (master-ready). The addressed slave fetches the data, drives it onto the bus and raises SSYN (slave-ready). The master latches the data and drops MSYN; the slave then removes the data and drops SSYN. Each signal waits for the other — a full (interlocked) handshake — so the transfer lasts exactly as long as the slave needs. Step through it in the sequence diagram on this page.
08Bus arbitration
When several masters want the bus at the same time, bus arbitration decides which one gets it; the winner keeps a bus-busy (BBSY) line asserted until it finishes. In centralised schemes a single arbiter decides:
Daisy chaining — all masters share one bus-request (BR) line, and the arbiter's bus-grant (BG) passes through the devices in series. The first requesting device on the chain absorbs the grant, so priority is fixed by position. Cheap and simple, but the grant ripples slowly, far devices can starve, and one faulty device breaks the chain.
Polling — the arbiter places device numbers on ⌈log₂N⌉ poll lines in turn; a requesting device that recognises its number takes the bus. Changing the polling order changes the priority, and a failed device is simply skipped.
Independent requests — every device has its own BR and BG lines to the arbiter, which grants at once using a priority encoder. Fastest and most flexible, but needs 2N lines.
Scheme
Arbitration lines (N devices) besides BBSY
Priority
Speed
Reliability
Daisy chaining
2 (BR shared, BG chained)
Fixed by position
Slow — the grant ripples
Poor — one failure breaks the chain
Polling
⌈log₂N⌉ poll lines + BR
Programmable
Medium
Good — dead devices are skipped
Independent requests
2N (BRᵢ and BGᵢ per device)
Programmable in the arbiter
Fastest
Good
In distributed arbitration there is no central arbiter. Each requesting device places its arbitration ID on shared open-collector (wired-OR) lines and withdraws when it sees a higher ID, so the highest-ID requester wins; SCSI and NuBus arbitrate this way.
PSC favourite
PSC patterns: “cheapest scheme, but with fixed priority?” → daisy chain; “a separate request–grant pair per device?” → independent requests; “which bus is unidirectional?” → address bus; “transmission capacity of a 32-line data bus?” → 32 bits in parallel.
Step through · Asynchronous bus read with a full handshake
step 1 / 8
Step 1: Address + READ command on bus
The master drives the address lines and the read command so every slave can begin decoding.
Worked examples
Try the problem first, then reveal the working one step at a time.
EX 1Address lines, data lines and bus bandwidth (PSC classic)
(a) A memory unit is 32K × 16. How many address and data lines does it need? (b) A byte-addressable CPU has a 24-bit address bus — how much memory can it address? (c) Its 32-bit data bus runs at 50 MHz and needs 2 clock cycles per transfer. What is the bus bandwidth?
EX 2Designing instruction formats
A processor has 32-bit instructions and 64 general-purpose registers. (a) Instructions of the form OP Rd, Rs, #imm carry a 14-bit immediate: how many opcodes are possible? (b) If every instruction were instead a three-register form OP Rd, Rs1, Rs2, how many bits would be left for the opcode?
EX 3A zero-address program with a stack trace
Write a zero-address program for X = A × B + C × D and trace the stack for A = 2, B = 3, C = 4, D = 5.
Practice session
Work each problem on paper first, then check. Marking one solved earns 10 XP.0/5 solved
Q1
A two-word LOAD instruction occupies addresses 600–601, its address field is 300, and PC = 602 after fetch. R1 = 250 and XR = 50. Memory holds M[249] = 640, M[250] = 125, M[300] = 450, M[350] = 520, M[450] = 700 and M[902] = 610. Find the EA and the operand for immediate, direct, indirect, relative, indexed, register indirect and autodecrement modes.
Q2
Write three-, two-, one- and zero-address programs for Y = (A − B) ÷ (C + D).
Q3
Six bus masters D1 … D6 share a bus, with D1 nearest the arbiter. (a) How many arbitration lines does each centralised scheme need, counting the common bus-busy line? (b) Under daisy chaining, D2, D4 and D5 request at the same moment. Which device gets the bus, and what risk does D5 face?
Q4
In Mano's 64-word register stack, SP = 63, FULL = 0 and EMTY = 0. Give SP, FULL and EMTY after (a) one PUSH, then (b) one POP, then (c) another POP.
Q5
A 32-bit synchronous bus has a 100 MHz clock. A memory read needs 1 cycle to send the address, 5 cycles for the memory access and 1 cycle to return the data. (a) What are the read time per word and the read bandwidth? (b) What changes with a faster memory needing only 3 access cycles?
Exam traps
MOV AX, 1562H is immediate (the number itself); MOV AX, [1562H] is direct (the contents of location 1562H). Square brackets mean “memory at”.
Relative addressing adds the updated PC (address of the next instruction), not the address of the branch instruction itself — off-by-instruction-length errors are the usual trap.
Indexed and base-register modes use the same arithmetic (register + address field). In indexed mode the address field holds the array start and the register the index; in base mode the register holds the base and the field the displacement.
The address bus is unidirectional; the data bus is bidirectional; the control bus as a whole carries signals both ways even though each control line is one-way, so options calling the control bus unidirectional are usually wrong.
Stack conventions vary: Mano's register stack increments SP before a push, memory stacks (Mano, 8086) usually grow downward, and SP may point to the top item or the next free slot.
n address lines give 2ⁿ addressable units. A 32K × 16 memory needs 15 address lines (not 16, and not 19 from counting bytes) plus 16 data lines.
Quiz — KPSC style
10 questions. 70 % passes the topic quiz (+30 XP, +20 more for 100 %). Exam scoring: +1 correct, −⅓ wrong.
Instruction formats, addressing & bus organization · Question 1 of 10✓ 0 · ✗ 0
Which of the following buses is unidirectional?
Past-paper questions on this topic
Modelled on real KPSC questions (reworded) with the same concept and answer; each links to its original paper.
Past papers · Question 1 of 6✓ 0 · ✗ 0
Modelled on QP 088/2023 · Assistant Professor in Computer Science and Engineering (23 Jun 2023), Q.21 (reworded)original paper (PDF)
A bus is made of 32 lines. How much data can it carry at once, in parallel?