Instruction set architecture and formats
What an instruction set architecture is, the classes of ISA by where operands live (stack, accumulator, register-memory, load-store), the same expression on each, endianness and alignment, condition codes, word size and address bits, and the code-size and speed trade-offs.
Why it exists
Software never sees transistors. It sees an instruction set architecture (ISA): the list of instructions, the registers, the ways to name memory and the data formats. Everything below the ISA (pipelines, caches, the number of ALUs) can change between processor generations while old programs keep running, and everything above it (compilers, operating systems) is written against it. Choices made in the ISA decide code size, how fast the hardware can be, and how hard the compiler's job is. GATE asks you to classify an ISA by its operand storage, to count instructions or memory references for an expression, to compute address bits, and to know what endianness and alignment mean.
Prerequisites
You need the instruction cycle from the instruction cycle and two's complement numbers from signed number representation.
Precise definitions
ISA. The programmer-visible interface of a processor: the instruction set and its encoding, the registers (number, width, special roles), the data types, the memory model (address size, byte order, alignment), the addressing modes, and how exceptions and interrupts are handled. The organization (how it is built) and the hardware (the technology) are separate and may change while the ISA stays.
Classification by operand storage. Where do the operands of an arithmetic instruction live?
| ISA class | Operands of ADD | Example |
|---|---|---|
| Stack (zero-address) | implicit: the top two stack entries | PUSH A, PUSH B, ADD |
| Accumulator (one-address) | the accumulator and one memory operand | ADD B |
| Register-memory | a register and a memory operand | ADD R1, B (x86 style) |
| Load-store (register-register) | only registers; separate LOAD and STORE for memory | ADD R1, R2, R3 (MIPS, ARM, RISC-V style) |
| Memory-memory | all operands in memory | ADD X, A, B (VAX style) |
Fewer explicit operands make instructions shorter and decoding simpler but need more instructions or more memory traffic; more explicit operands do more work per instruction but make instructions long and slow to decode.
Number of addresses in an instruction. Three-address: . Two-address: (the destination is also a source). One-address: uses an implied accumulator. Zero-address: stack operands. Instruction formats and the opcode space are treated in formats and expanding opcodes.
Types of operations. Data transfer (load, store, move, push, pop), arithmetic and logic (add, subtract, multiply, shifts, compare, and so on), control flow (jump, conditional branch, call, return), system (traps, privileged instructions, I/O), and floating point.
Memory model.
- Byte addressing. Each address names one byte. A memory with an -bit address holds bytes. With a word-addressable memory each address names a word, so address bits name words.
- Endianness. Which byte of a multi-byte value goes at the lowest address. Little-endian: the least significant byte at the lowest address. Big-endian: the most significant byte first. The value at address is stored (lowest address first) as 78 56 34 12 in little-endian and 12 34 56 78 in big-endian.
- Alignment. A -byte datum is aligned if its address is a multiple of . Aligned accesses are one memory transfer; misaligned ones may need two, or may be forbidden. Compilers add padding to keep structure fields aligned.
Control-flow conditions. Two styles: condition codes (flags N, Z, C, V set by arithmetic and compare instructions, then tested by conditional branches: see fixed-point arithmetic for how unsigned and signed comparisons use and ) and compare-and-branch (one instruction compares two registers and branches, with no flags).
Instruction length. Fixed length (all instructions the same size, such as 4 bytes) makes fetch and decode simple and pipelining easy; variable length gives smaller programs but harder decoding.
Cost of the ISA choice. Execution time = instruction count CPI clock period. The ISA mainly sets the first factor and limits the others.
How it works
The best way to see the difference between ISA classes is to run the same expression, , on each of them. The animation shows the zero-address (stack) machine: ADD and MUL carry no operand addresses at all, they work on the top of the stack, with the stack growing toward lower addresses.
Zero-address machine: X = (A + B) * (C + D): step 1
Machine run, not typed(start)| addr | decimal | meaning | |
|---|---|---|---|
| 00A | 1 | A | |
| 00B | 2 | B | |
| 00C | 3 | C | |
| 00D | 4 | D | |
| 00E | 0 | X | |
| 0CC | . | stack | |
| 0CB | . | stack | |
| 0CA | . | stack | |
| 0C9 | . | stack | |
| 0C8 | . | stack |
Step 1
A zero-address machine has no accumulator and no named operands for the arithmetic: ADD and MUL take their operands from the top of a stack and leave the result there. The stack grows toward lower addresses; SP points at the top word (205 means empty). Variables A, B, C, D = 1, 2, 3, 4 are at addresses 10 to 13 and X will be written at 14. The task is X = (A + B) * (C + D).
The five instruction sequences (written out in the examples below) are each executed by a small interpreter and give the same answer. The cost differs:
| ISA class | instructions | data reads | data writes | code bytes (assumed encoding) |
|---|---|---|---|---|
| three-address memory-memory | 3 | 6 | 3 | 21 |
| two-address memory-memory | 6 | 9 | 6 | 30 |
| accumulator | 7 | 5 | 2 | 21 |
| stack | 8 | 4 | 1 | 18 |
| load-store | 8 | 4 | 1 | 32 |
(Code bytes assume a 1-byte opcode and 2-byte memory addresses, and 4-byte fixed instructions for the load-store machine. The point is the comparison, not the absolute numbers: the stack and register machines touch memory least, the memory-memory machines need the fewest instructions but the most data traffic.)
Worked examples
EX 1One expression, five instruction sequences
EasyFor :
Three-address (memory to memory): ADD T1, A, B; ADD T2, C, D; MUL X, T1, T2 (3 instructions).
Two-address: MOV T1, A; ADD T1, B; MOV T2, C; ADD T2, D; MUL T1, T2; MOV X, T1 (6).
One-address (accumulator): LOAD A; ADD B; STORE T; LOAD C; ADD D; MUL T; STORE X (7).
Zero-address (stack): PUSH A; PUSH B; ADD; PUSH C; PUSH D; ADD; MUL; POP X (8).
Load-store: LOAD R1, A; LOAD R2, B; ADD R1, R1, R2; LOAD R2, C; LOAD R3, D; ADD R2, R2, R3; MUL R1, R1, R2; STORE X, R1 (8).
Each sequence is run by an interpreter in the checking script and produces for . Fewer instructions does not mean faster: the memory-memory sequences use fewer instructions but read and write memory more often.
EX 2Byte order and structure padding
Easy#include <stdio.h>
#include <stdint.h>
#include <stddef.h>
struct padded { char c; int i; char d; };
struct packed_order { int i; char c; char d; };
int main(void) {
union { uint32_t word; uint8_t byte[4]; } u = { 0x12345678u };
printf("word 12345678 is stored as bytes %02X %02X %02X %02X (byte 0 first)\n", u.byte[0], u.byte[1], u.byte[2], u.byte[3]);
printf("so this machine is %s-endian\n", u.byte[0] == 0x78 ? "little" : "big");
printf("struct padded: size %zu, offsets %zu %zu %zu\n", sizeof(struct padded), offsetof(struct padded, c), offsetof(struct padded, i), offsetof(struct padded, d));
printf("struct packed_order: size %zu, offsets %zu %zu %zu\n", sizeof(struct packed_order), offsetof(struct packed_order, i), offsetof(struct packed_order, c), offsetof(struct packed_order, d));
uint32_t swapped = ((u.word & 0xFF) << 24) | ((u.word & 0xFF00) << 8) | ((u.word >> 8) & 0xFF00) | (u.word >> 24);
printf("the same bytes read in the other order: %08X\n", swapped);
return 0;
}word 12345678 is stored as bytes 78 56 34 12 (byte 0 first)
so this machine is little-endian
struct padded: size 12, offsets 0 4 8
struct packed_order: size 8, offsets 0 4 5
the same bytes read in the other order: 78563412The first lines show little-endian storage (byte 0, the lowest address, holds 78). Reading the same four bytes as a big-endian number gives 78563412, which is why files and network packets must agree on byte order. The structure with a char, an int, and a char is padded to 12 bytes (the int must sit at an offset that is a multiple of 4, and the whole structure is rounded up to a multiple of 4); putting the int first gives 8 bytes. These sizes are for the usual 4-byte int with natural alignment.
EX 3Address bits and capacity
Medium(a) A byte-addressable memory of 64 MB needs address bits. (b) If the same memory is word-addressable with 4-byte words there are words and 24 address bits are needed. (c) With 32 address bits and 2-byte words, the capacity is GB. (d) To address 3000 different words requires bits.
EX 4Code size against memory traffic
MediumWith a 1-byte opcode and 2-byte memory addresses: the stack sequence needs 5 instructions with an address (PUSH , POP , 3 bytes each) and 3 without (1 byte): 18 bytes. The accumulator sequence has 7 instructions of 3 bytes: 21 bytes. The three-address sequence has 3 instructions of bytes: 21 bytes. The load-store sequence has 8 fixed 4-byte instructions: 32 bytes. The stack machine has the smallest code and the fewest data references (5, tied with the load-store machine), and the two-address memory machine has the most (15), because it keeps temporaries in memory.
EX 5Which branch condition for which comparison?
GATE levelAfter computing the flags are set (with carry meaning "no borrow", as in fixed-point arithmetic). Branch if equal: . Branch if not equal: . Signed less than: . Signed greater or equal: . Unsigned lower: (a borrow occurred). Unsigned higher or same: . A compare-and-branch ISA has no flags: BLT R1, R2, label does the comparison and the jump in one instruction (a signed BLT, and a separate unsigned BLTU).
EX 6Classify the ISA
GATE levelAn instruction ADD R1, R2, R3 with only register operands, and separate LW R1, 8(R2) and SW R1, 8(R2) for memory, belongs to a load-store ISA. ADD R1, 8(R2) (one register and one memory operand) is register-memory. ADD X, Y, Z with three memory addresses is memory-memory. An instruction ADD with no operands that pops two values and pushes the sum is stack (zero-address). ADD 100 that adds the memory word at 100 to the accumulator is accumulator. A load-store ISA typically has fixed-length instructions and many registers, so the compiler can keep values in registers.
Cheat box
Cheat box
- ISA = the software-visible interface; organization and hardware can change under it.
- Classes: stack (0 operands named), accumulator (1), register-memory, load-store (registers only; memory only by LOAD and STORE), memory-memory.
- : 3-address 3 instructions, 2-address 6, accumulator 7, stack 8, load-store 8.
- Byte addressing: bits give bytes; word addressing: words. Little-endian: least significant byte at the lowest address.
- Aligned: address divisible by the size. Padding aligns structure fields.
- Branches: condition codes (flags) or compare-and-branch. Unsigned lower: after a subtraction; signed less: .
- Fixed length: simple decode, pipelining-friendly; variable: dense code.
Traps and GATE patterns
Connections
Builds on
Unlocks
Across subjects
Within this subject
The fields that fit into one instruction word and the number of opcodes available are the subject of instruction formats and expanding opcodes. How an operand is named is addressing modes. The contrast between the two main philosophies of ISA design is RISC versus CISC, and the hardware that runs each instruction is described in the datapath. The flags are the same ones produced by the adder of fixed-point arithmetic.
PYQs
6 previous year questions from your book. I re-solved each one myself (3 by running or simulating, 3 by reasoning only); the book's key is shown next to my answer. All PYQs
If the numerical value of a 2-byte unsigned integer on a little endian computer is 255 more than that on a big endian computer, which of the following choices represent(s) the unsigned integer on a little endian computer?
- (a)0x6665
- (b)0x 0001
- (c)0x4243
- (d)0x 0100
Consider a processor P whose instruction set architecture is the load-store architecture. The instruction format is such that the first operand of any instruction is the destination operand. Which one of the following sequences of instructions corresponds to the high-level language statement Z = X + Y? Note: X, Y, and Z are memory operands. R0, R1, and R2 are registers.
- (a)ADD Z, X, Y
- (b)LOAD R0, X ADD Z, R0, Y
- (c)ADD R0, X, Y STORE Z, R0
- (d)LOAD R0, X LOAD R1, Y ADD R2, R0, R1 STORE Z, R2
An application executes 6.4 × 108 number of instructions in 6.3 seconds. There are four types of instructions, the details of which are given in the table. The duration of a clock cycle in nanoseconds is (rounded off to one decimal place). Instruction type Clock cycles required per instruction (CPI) Number of instruction executed Branch 2 2.25 × 108 Load 5 1.20 × 108 Store 4 1.65 × 108 Arithmetic 3 1.30 × 108 3 3 Computer Organization and Architecture
Which of the following is/are part of an Instruction Set Architecture of a processor?
- (a)The size of the cache memory
- (b)The clock frequency of the processor
- (c)The number of cache memory levels
- (d)The total number of registers
Consider the given C-code and its corresponding assembly code, with a few operands U1-U4 being unknown. Some useful information as well as the semantics of each unique assembly instruction is annotated as inline comments in the code. The memory is byte-addressable. ;assembly code (; indicates comments) ;r1-r5 are 32-bit integer registers //C-code ;initialize r1=0, r2=10 ;initialize r3, r4 with base address of a, b L01: jeq r1, r2, end ;if(r1==r2) goto end L02: lw, r5, 0(r4) ;r5 <- Memory[r4+0] int a[10], b[10], i; L03: sh1, r5, r5, U1 ;r5 <- r5 << U1 // int is 32 bit L04: sw, r5, 0(r3) ;Memory[r3+0] <- r5 for(i=0; i<10; i++) L05: add, r3, r3, U2 ;r3 <- r3+U2 a[i] = b[i] * 8; L06: add, r4, r4, U3 L07: add, r1, r1, 1 L08: jmp U4 ;goto U4 L09: end Which one of the following options is a CORRECT replacement for operands in the position (U1, U2, U3, U4) in the above assembly code?
- (a)(8, 4, 1, L02)
- (b)(3, 4, 4, L01)
- (c)(8, 1, 1, L02)
- (d)(3, 1, 1, L01) Computer Organization and Architecture
In a simplified computer the instructions are: OP Rj, Ri Perform Rj OP Ri and store the result in register Rj OP m, Ri Perform val OP Ri and store the result in register Ri val denotes the content of the memory location m MOV m, Ri Moves the content of memory location m to register Ri MOV Ri, m Moves the content of register Ri to memory location m The computer has only two registers, and OP is either ADD or SUB. Consider the following basic block: t1 = a + b t2 = c + d t3 = e - t2 t4 = t1 - t3 Assume that all operands are initially in memory. The final value of the computation should be in memory. What is the minimum number of MOV instructions in the code generated for this basic block?
- (a)2
- (b)3
- (c)5
- (d)6
Self-check
Question 1
How many instructions does X = A * B + C * D take on a stack machine with PUSH, POP, ADD and MUL?
Show answerHide
PUSH A, PUSH B, MUL, PUSH C, PUSH D, MUL, ADD, POP X: 8 instructions.
Question 2
A byte-addressable machine stores the 32-bit value 0xAABBCCDD at address 1000. What byte is at address 1000 in little-endian and in big-endian?
Show answerHide
Little-endian: the least significant byte, DD, at 1000. Big-endian: the most significant byte, AA, at 1000.
Question 3
A word-addressable memory has 2^20 words of 16 bits. How many address bits, and what is the capacity in bytes?
Show answerHide
20 address bits; capacity MB.
Question 4
In a load-store ISA, which instructions may access memory?
Show answerHide
Only the load and store instructions. All arithmetic and logic instructions use registers.
Revision card
One-screen revision
- ISA = software-visible interface. Classes: stack, accumulator, register-memory, load-store, memory-memory.
- : 3 / 6 / 7 / 8 / 8 instructions; load-store and stack touch memory least.
- Capacity unit. Little-endian: LSB at lowest address. Aligned = address multiple of size.
- Signed less ; unsigned lower . Fixed length = simple decode.
References
- ·Hennessy and Patterson, Computer Architecture: A Quantitative Approach, Appendix A / Chapter 1 Instruction Set Principles (classifying ISAs, memory addressing, operations)
- ·Hennessy and Patterson, Computer Organization and Design, Chapter 2 Instructions: Language of the Computer
- ·Hamacher, Vranesic, Zaky, Computer Organization, 5th ed., Chapter 2 Machine Instructions and Programs
Verification
The five instruction styles are implemented as interpreters in scripts/enum-checks/coa_isa.py and run on the same expression: instruction counts, data memory references and code sizes quoted here are those programs' counts (the code sizes assume 1-byte opcodes, 2-byte addresses and 4-byte fixed instructions, stated as assumptions). The stack-machine animation is a simulator run re-checked in tests/coa-traces.test.ts. Address-bit and capacity arithmetic is checked in the script, and the endianness and padding facts are shown by a C program compiled and run by npm run verify:c (the output is for a little-endian machine with 4-byte int and natural alignment, as on common desktop hardware). Textbook chapter titles are from memory. SECOND PASS (2026-11-02, done by the assistant, not a human check): every Self-check question was solved before the printed answer was read and all agreed; the definitions, worked examples, cheat box and traps were read claim by claim and the numbers re-derived by hand (long C programs were not re-read line by line: they are compiled and compared by npm run verify:c, and their printed outputs were checked against the prose). No defect found. Status raised to self-checked; verified needs a textbook or human check.
last verified: never
My notes (saved in this browser)