G27
Self-checkedTier 1 12 min readcoa.isa-design

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 classOperands of ADDExample
Stack (zero-address)implicit: the top two stack entriesPUSH A, PUSH B, ADD
Accumulator (one-address)the accumulator and one memory operandADD B
Register-memorya register and a memory operandADD R1, B (x86 style)
Load-store (register-register)only registers; separate LOAD and STORE for memoryADD R1, R2, R3 (MIPS, ARM, RISC-V style)
Memory-memoryall operands in memoryADD 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: X←Y∘ZX \leftarrow Y \circ Z. Two-address: X←X∘YX \leftarrow X \circ Y (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 nn-bit address holds 2n2^n bytes. With a word-addressable memory each address names a word, so nn address bits name 2n2^n 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 0x12345678\texttt{0x12345678} at address aa is stored (lowest address first) as 78 56 34 12 in little-endian and 12 34 56 78 in big-endian.
  • Alignment. A kk-byte datum is aligned if its address is a multiple of kk. 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 CC and N⊕VN \oplus V) 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 ×\times CPI ×\times 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, X=(A+B)×(C+D)X = (A + B) \times (C + D), 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(start)
PC
0
SP
205
MDR
0
addrdecimalmeaning
00A1A
00B2B
00C3C
00D4D
00E0X
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).

1 / 21
computed by script: a simulation of the machine, one register transfer per step. python3 scripts/gen-coa-traces.py

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 classinstructionsdata readsdata writescode bytes (assumed encoding)
three-address memory-memory36321
two-address memory-memory69630
accumulator75221
stack84118
load-store84132

(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

Easy

For X=(A+B)×(C+D)X = (A + B) \times (C + D):

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 (1+2)×(3+4)=21(1+2)\times(3+4) = 21 for A,B,C,D=1,2,3,4A, B, C, D = 1, 2, 3, 4. 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: 78563412

The 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 log⁡2(64×220)=26\log_2 (64 \times 2^{20}) = 26 address bits. (b) If the same memory is word-addressable with 4-byte words there are 2242^{24} words and 24 address bits are needed. (c) With 32 address bits and 2-byte words, the capacity is 232×2=82^{32} \times 2 = 8 GB. (d) To address 3000 different words requires ⌈log⁡23000⌉=12\lceil \log_2 3000 \rceil = 12 bits.

EX 4Code size against memory traffic

Medium

With a 1-byte opcode and 2-byte memory addresses: the stack sequence needs 5 instructions with an address (PUSH ×4\times 4, POP ×1\times 1, 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 1+3×2=71 + 3 \times 2 = 7 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 level

After computing A−BA - B the flags N,Z,C,VN, Z, C, V are set (with carry meaning "no borrow", as in fixed-point arithmetic). Branch if equal: Z=1Z = 1. Branch if not equal: Z=0Z = 0. Signed less than: N⊕V=1N \oplus V = 1. Signed greater or equal: N⊕V=0N \oplus V = 0. Unsigned lower: C=0C = 0 (a borrow occurred). Unsigned higher or same: C=1C = 1. 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 level

An 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.
  • X=(A+B)(C+D)X = (A+B)(C+D): 3-address 3 instructions, 2-address 6, accumulator 7, stack 8, load-store 8.
  • Byte addressing: nn bits give 2n2^n bytes; word addressing: 2n2^n 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: C=0C = 0 after a subtraction; signed less: N⊕VN \oplus V.
  • Fixed length: simple decode, pipelining-friendly; variable: dense code.

Traps and GATE patterns

Connections

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

GATE 2021 · MSQQ2 · page 451 of the book
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
GATE 2026 · MCQQ1 · page 474 of the book
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
GATE 2025 · NATQ4 · page 474 of the book
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
GATE 2025 · MCQQ5 · page 475 of the book
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
GATE 2023 · MCQ · 2 marksQ9 · page 475 of the book
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
year not read yetQ28 · page 480 of the book
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 answer

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 answer

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 answer

20 address bits; capacity 220×2=22^{20} \times 2 = 2 MB.

Question 4

In a load-store ISA, which instructions may access memory?

Show answer

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.
  • (A+B)(C+D)(A+B)(C+D): 3 / 6 / 7 / 8 / 8 instructions; load-store and stack touch memory least.
  • Capacity =2bits×= 2^{\text{bits}} \times unit. Little-endian: LSB at lowest address. Aligned = address multiple of size.
  • Signed less =N⊕V= N \oplus V; unsigned lower =(C=0)= (C = 0). 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