Instructions, operands and addresses
An instruction describes an operation and where its operands come from. First separate architectural rules from the hardware that implements them; then count fields and trace addresses in the units the machine actually uses.
1.1 Instruction set and machine state
Past papers · CS 2014–2026 (23 papers): 4 questions, 4 marks
The instruction set architecture (ISA) specifies programmer-visible registers, instruction encodings and semantics, supported operand types, addressing modes and architectural memory behaviour. Cache capacity, pipeline depth and clock frequency are implementation choices. Two implementations of the same ISA can execute the same binary at different speeds.
| Instruction class | State change | Question-solving cue |
|---|---|---|
| Load/store or move | Transfer data between specified locations | Distinguish the address from its contents |
| Arithmetic/logic | Compute a register or memory result | Check destination position and flag updates |
| Shift/rotate | Reposition bits | Identify signedness and shifted-in bits |
| Conditional branch | Change PC only if a condition holds | Use the flags from the instruction that last changes them |
| Call/return | Transfer control and preserve/recover a return address | Do not assume a particular stack convention |
| Input/output | Access a peripheral interface | I/O address space may be separate from memory |
PC is the program counter; IR holds the fetched instruction; a status register or PSW holds condition flags and other architectural status. Register names and flag behaviour are ISA-dependent.
A load-store ISA performs ordinary arithmetic on registers; explicit loads and stores transfer memory operands. Classic RISC designs favour regular formats, register operands and hardwired control. Classic CISC designs often provide more addressing modes and variable instruction lengths. These are design tendencies, not definitions that determine every modern implementation.
| Explicit operand addresses | Typical arithmetic semantics | Implicit information |
|---|---|---|
| Three | ADD D, A, B: | Next PC normally sequential |
| Two | ADD D, S: | Destination is also a source |
| One | ADD A: accumulator accumulator | Accumulator |
| Zero | ADD: pop two operands, push their sum | Stack top operands |
Here denotes memory contents at address . An operand-address field can select a register or a memory operand if the ISA permits it. An implied accumulator requires no explicit address field.
1.2 Fixed instruction fields
Past papers · CS 2014–2026 (23 papers): 6 questions, 10 marks · EC 2020–2026 (7 papers): 1 question, 1 mark
Count encoded choices, not the largest register number written in the question. A register used both as source and destination needs only one field when the instruction format specifies that shared field.
If a type bit partitions the instruction set, budget that bit and the operation bits within the largest type separately. Unused register encodings do not automatically become opcode bits. A fixed -bit opcode supports at most operations when all patterns are available.
1.3 Expanding opcodes
Past papers · CS 2014–2026 (23 papers): 3 questions, 6 marks
Short opcode prefixes can leave more operand bits; longer prefixes reuse only unallocated regions. The decoder must distinguish formats without mistaking part of an operand for an opcode.
1.4 Effective addresses
Past papers · CS 2014–2026 (23 papers): 5 questions, 8 marks
An effective address, EA, identifies the operand's memory location. An immediate is already the operand, and register-direct addressing has no memory EA. In the table, is an instruction field, are register contents and is an index scale in addressable units per element.
For a read operand, direct and register-indirect addressing need one data-memory access; memory-indirect needs an extra pointer read. This count excludes fetching instruction bytes, translation and cache effects. Stores and read-modify-write instructions require their own access count.
1.5 Data layout and byte order
Past papers · CS 2014–2026 (23 papers): 2 questions, 4 marks
Byte addressing means each byte has an address; a 32-bit word then spans four addresses. Word addressing gives one address per word. Endianness orders bytes within a multi-byte value, not bits inside a byte.
Natural alignment of a -byte object means its address is divisible by . A compiler may insert padding between record fields; use the stated layout rather than summing sizes blindly.
1.6 Stack and subroutine discipline
Past papers · CS 2014–2026 (23 papers): 1 question, 2 marks · EC 2020–2026 (7 papers): 1 question, 2 marks
A stack is last-in, first-out. PUSH/POP ordering and stack growth are independent of byte order. CALL preserves the return PC, sometimes in a link register; an interrupt may also preserve status. Only save additional words if the stated mechanism requires them.
Last-minute recall
- ISA describes visible behaviour; cache size and clock rate describe an implementation.
- Round each independent field width upward before subtracting it from the instruction length.
- Expanding opcodes consume complete encoding regions, not equal-sized opcode slots.
- A memory-indirect operand needs a pointer read before its data read.
- Resolve PC reference and displacement scale before calculating a branch target.
- Endianness changes byte significance; address progression still increases by one byte.
- Track stack direction, item width and what SP points to separately.