Learning Outcomes
SLO | After this lecture you can… | CLO | Bloom |
|---|---|---|---|
SLO 7.1 | Classify an instruction set by where its operands are kept: stack, accumulator, register-memory, load-store or memory-memory. | CLO3 | C2 Understand |
SLO 7.2 | Write code for a simple expression in each class and count instructions, memory accesses and code size. | CLO3 | C3 Apply |
SLO 7.3 | Explain the advantages and disadvantages of each class, and why modern ISAs are load-store (RISC). | CLO3 | C2 Understand |
§1 Where Do Operands Live?
§1.1 What an instruction set architecture is
Slide L07-S06
The instruction set architecture (ISA) is the part of a computer that the programmer and the compiler can see. It is the contract (agreement) between software and hardware: software is written for the ISA, not for one particular chip. Real-world example: the three-pin plug standard in Pakistan - any iron or fan with that plug works in any socket, whatever company made it.
Hennessy and Patterson describe an ISA along seven dimensions. Unit 2 covers them in this order:
Dimension | Question it answers | Lecture |
|---|---|---|
Class of ISA | Where does the processor keep its operands? | 7 (today) |
Memory addressing | How are bytes numbered? Must data be aligned? Which byte order? | 8 |
Addressing modes | How does an instruction say where its operand is? | 8 |
Types and sizes of operands | Bytes, half words, words, floating point… | 8-9 |
Operations | Arithmetic, logical, data transfer, floating point… | 9 |
Control flow | Branches, jumps, procedure calls | 9 |
Encoding | Fixed or variable instruction length | 10 |
§1.2 Four kinds of internal storage
Slide L07-S07
The most basic difference between ISAs is the kind of storage the processor uses for operands (the values an instruction works on).
Class | Where the operands are | Operands named in an ALU instruction | Real-world example |
|---|---|---|---|
Stack | On the top of a stack | None (implicit = understood without naming) | A pile of plates at a wedding: only the top plate can be taken |
Accumulator | One operand is always the accumulator register | One (the other is the accumulator) | The display of a shop calculator that keeps the running total |
Register-memory | Registers; one operand may be in memory | All (explicit) | Cashier who may take one item straight from the shelf |
Load-store (register-register) | Registers only; only load and store touch memory | All (explicit) | Cashier who first puts every item in a labelled tray |
§1.3 Memory operands and total operands
Slide L07-S08
Register machines are described by two numbers for an ALU instruction: (maximum number of memory operands, total number of operands).
(Memory, total) | Class | Examples |
|---|---|---|
(0, 3) | Load-store (register-register) | MIPS, ARM, RISC-V, SPARC, PowerPC |
(1, 2) | Register-memory | Intel x86, IBM 360/370, Motorola 68000 |
(2, 2) | Memory-memory | VAX |
(3, 3) | Memory-memory | VAX |
MIPS (0,3): add $t3, $t0, $t1 # $t3 = $t0 + $t1, registers only |
In a two-operand instruction one source is destroyed, because it also receives the result (EAX above).
§2 C = A + B in Every Class
§2.1 The code
Slide L07-S10
A, B and C are variables in memory (Hennessy and Patterson, Figure A.2).
Stack | Accumulator | Register-memory | Load-store |
|---|---|---|---|
Push A | Load A | Load R1, A | Load R1, A |
Push B | Add B | Add R3, R1, B | Load R2, B |
Add | Store C | Store R3, C | Add R3, R1, R2 |
Pop C | Store R3, C |
Add on a stack machine pops the two top values, adds them and pushes the result. On MIPS (load-store) the same statement is:
lw $t0, A |
§2.2 Counting instructions, memory accesses and code size
Slide L07-S11
Assume an opcode takes 8 bits, a memory address 32 bits and a register number 5 bits (32 registers).
Stack | Accumulator | Register-memory | Load-store | |
|---|---|---|---|---|
Instructions | 4 | 3 | 3 | 4 |
Data memory accesses | 3 | 3 | 3 | 3 |
Code size (bits) | 40 + 40 + 8 + 40 = 128 | 3 x 40 = 120 | 45 + 50 + 45 = 140 | 45 + 45 + 23 + 45 = 158 |
Code size (bytes) | 16 | 15 | 17.5 | 19.75 |
For this tiny statement the load-store code is the largest. That changes when values are reused.
§2.3 Worked example: D = (A + B) x (A - C)
Slide L07-S12
Class | Code | Instructions | Data accesses |
|---|---|---|---|
Stack | Push A; Push B; Add; Push A; Push C; Sub; Mul; Pop D | 8 | 5 |
Accumulator | Load A; Add B; Store T; Load A; Sub C; Mul T; Store D | 7 | 7 |
Register-memory | Load R1, A; Add R2, R1, B; Sub R3, R1, C; Mul R4, R2, R3; Store R4, D | 5 | 4 |
Load-store | Load R1, A; Load R2, B; Load R3, C; Add R4, R1, R2; Sub R5, R1, R3; Mul R6, R4, R5; Store R6, D | 7 | 4 |
Memory-memory | Add T, A, B; Sub D, A, C; Mul D, T, D | 3 | 9 |
The accumulator machine has only one register, so A + B must be saved in a temporary T in memory. The memory-memory machine has the fewest instructions but the most memory accesses (each instruction reads two operands and writes one). Registers keep A and the temporaries inside the processor, so memory traffic is lowest. Because memory is much slower than registers (Lecture 2), data accesses matter more than the instruction count.
# D = (A + B) * (A - C) on MIPS, tested in MARS 4.5 with A = 7, B = 5, C = 3 |
§2.4 Stack machines are still alive
Slide L07-S13
Hardware stack machines (Burroughs B5000, the x87 floating-point unit) have mostly gone, but stack ISAs are common as virtual machines: Java bytecode, Python bytecode and WebAssembly. Stack code is compact (no register names) and easy for a compiler to generate; the virtual machine then translates it for the real processor. Real output of Python 3.13 for y = a * b + c:
LOAD_FAST_LOAD_FAST 1 (a, b) # push a and b |
Java compiles c = a + b to iload_1, iload_2, iadd, istore_3. Accumulator machines also live on: the Intel 8085 used in many microprocessor labs in Pakistan uses register A as its accumulator.
§3 Why Registers Won
§3.1 Three reasons
Slide L07-S15
Reason | Explanation |
|---|---|
Speed | Registers are inside the processor; memory is far away and much slower. |
Compilers | Registers can be used in any order. For (A x B) - (B x C) - (A x D) a stack forces one order of evaluation. Variables can stay in registers, so memory traffic falls. |
Code density | A register is named with 5 bits (32 registers); a memory address needs 32 bits. |
Real-world: a carpenter keeps the tools he uses all day on his workbench (registers), not in the store room (memory).
§3.2 Advantages and disadvantages
Slide L07-S16
Class | Advantages | Disadvantages |
|---|---|---|
Load-store (0, 3) | Simple, fixed-length encoding; simple code generation; instructions take a similar number of clock cycles, so they pipeline well | Higher instruction count than designs with memory operands; larger programs |
Register-memory (1, 2) | Data can be used without a separate load; easy to encode; good code density | One source is destroyed; the memory address leaves fewer bits for register numbers; clock cycles per instruction vary with operand location |
Memory-memory (2, 2) or (3, 3) | Most compact; does not waste registers on temporaries | Large variation in instruction size and in work per instruction; memory accesses create a memory bottleneck. Not used today. |
§3.3 How many registers?
Slide L07-S17
ISA | Integer registers | Bits to name one |
|---|---|---|
MIPS32 | 32 (plus 32 floating-point) | 5 |
RISC-V | 32 (x0 is always 0) | 5 |
ARMv8 AArch64 (Android phones, Apple M-series) | 31 general registers | 5 |
x86-64 | 16 | 4 |
x86 (32-bit) | 8 | 3 |
More registers let the compiler keep more variables in the processor, so there are fewer loads and stores. The cost: more bits in every instruction, and more registers to save when the operating system switches between programs (a context switch).
§3.4 RISC versus CISC
Slide L07-S18
CISC (complex instruction set computer) | RISC (reduced instruction set computer) | |
|---|---|---|
Examples | Intel and AMD x86 | MIPS, ARM, RISC-V |
Class | Register-memory | Load-store |
Instruction length | Variable, 1 to 15 bytes | Fixed, 4 bytes |
Instructions | Many, some very complex | Fewer, simple |
Today the line is blurred: x86 processors split each instruction into simple RISC-like micro-operations inside the chip. Real-world: your phone runs ARM (RISC); most laboratory PCs run x86 (CISC). In MARS, only lw and sw touch memory; add cannot - MIPS is a pure load-store ISA.
§4 Common Mistakes
Slide L07-S20
Wrong idea | Correct idea |
|---|---|
Fewer instructions always means faster. | Count memory accesses too: memory-memory code has 3 instructions but 9 data accesses. |
A stack machine has no memory accesses. | Push and Pop are memory accesses; only the arithmetic instructions are not. |
MIPS add can use a memory operand. | MIPS is load-store: only lw and sw (and other loads/stores) touch memory. |
RISC means fewer registers. | RISC means simple, fixed-length instructions; RISC ISAs usually have more registers. |
Word Bank
Word | Simple meaning | Real-world example |
|---|---|---|
Operand | A value that an instruction works on | The two numbers you add on a calculator |
Implicit | Understood without being named | 'The usual' order at your regular tea stall |
Explicit | Named clearly | Ordering 'one doodh patti, half sugar' |
Stack | Storage where only the top item is used | A pile of plates |
Accumulator | A single register that holds the running result | Calculator display |
General-purpose register (GPR) | A named register usable for any data | A labelled tray in a cashier's drawer |
Load-store | Only load and store instructions access memory | Take items to the counter before billing |
Code density | How much work fits in a given number of bytes of code | Short SMS abbreviations |
Context switch | Saving one program's registers to run another | Packing your desk before another clerk sits |
Micro-operation | Simple internal step that a complex instruction is split into | A recipe split into simple steps |
Self-Check Questions
- Name the seven dimensions of an ISA. (§1.1)
- Name the four main classes of ISA and give a real machine for each. (§1.2, §2.4)
- What does (1, 2) mean? Which class is it? (§1.3)
- Write C = A + B for all four classes. (§2.1)
- With opcode 8, address 32 and register 5 bits, find the code size of each C = A + B sequence. (§2.2)
- Why does memory-memory code for D = (A + B) x (A - C) need 9 data accesses? (§2.3)
- Why are Java and Python bytecode stack based? (§2.4)
- Give three reasons why general-purpose registers won. (§3.1)
- Give one advantage and one disadvantage of load-store ISAs. (§3.2)
Answers: code sizes 128, 120, 140 and 158 bits; memory-memory: 3 instructions x 3 operands each, all in memory.
Further Reading
- Hennessy and Patterson (2012): Appendix A, sections A.1-A.2 (classifying instruction set architectures).
- Patterson and Hennessy, Computer Organization and Design: Chapter 2, sections 2.1-2.3 (MIPS operands and the load-store design).