Sub topic 1
What an instruction set architecture defines
Prerequisites
This chapter assumes you know the following:
- Binary and hexadecimal numbers, including how many bits you need to count N items.
- Basic digital logic: gates, multiplexers and flip-flops.
- What a register and a memory are, at the level of "registers are small and fast, memory is large and slow".
Later chapters cover the instruction cycle, formats, addressing modes, the ALU and the control unit in detail. This chapter only sets the boundary between what the programmer sees and what the hardware builder chooses.
The ISA as a contract
An instruction set architecture (ISA) is the contract between software and a processor. It lists everything a machine-code programmer, compiler or operating system must know to produce correct programs. It says nothing about how the hardware delivers that behavior.
If two processors implement the same ISA, the same binary runs on both and gives the same results. They may differ in speed, power and cost. This is why a program compiled for x86 still runs on a processor ten years newer.
What the ISA specifies
| Item | What it fixes | Example |
|---|---|---|
| Operations | The set of instructions and what each does | ADD, LOAD, STORE, BRANCH |
| Data types | Operand sizes and formats | 8/16/32/64-bit integers, IEEE 754 floats |
| Registers | The visible registers, their number and width | 16 general registers, a program counter, a status register |
| Addressing modes | How an instruction names an operand | Immediate, direct, indirect, indexed |
| Instruction format | How fields are packed into bits | 4-bit opcode, 4-bit register, 8-bit address |
| Memory model | Address size, addressable unit, byte order, alignment | Byte-addressable, little-endian |
| Control of the machine | Interrupts, exceptions, privilege levels, I/O access | User and kernel mode, trap instructions |
What the ISA leaves out
The implementation of an ISA is called its organization or microarchitecture. These choices are invisible to a correct program:
- Whether the control unit is hardwired or microprogrammed.
- Pipeline depth, cache sizes and branch predictors.
- Whether the adder is ripple-carry or carry-lookahead.
- The width of the internal buses.
The ISA is the line in this diagram that does not change when the layers below it do.
The visible state of the machine
A program can observe and change only the architectural state. This consists of the following:
- The general-purpose registers.
- The program counter (PC), which holds the address of the next instruction.
- The status register, which holds flags such as zero, negative, carry and overflow. A later chapter covers these.
- Memory.
Hidden registers such as the instruction register, the memory address register and the memory data register exist in most designs. They are part of the datapath, not the ISA, so a different implementation could drop them.
Instruction categories
Most ISAs group their instructions into the same few classes:
- Data transfer: move data between registers and memory (LOAD, STORE, MOV, PUSH, POP).
- Arithmetic and logic: ADD, SUB, AND, OR, shifts and compares.
- Control flow: jumps, conditional branches, calls and returns.
- System: traps, interrupt return, halt and privileged I/O instructions.
Memory model details that affect answers
Addressable unit and address width
Most machines are byte-addressable, which means each address names one byte. The number of address bits decides how much memory the program can name:
- N address bits name 2^N locations.
- A 64 MB byte-addressable memory is 2^26 bytes, so it needs 26 address bits.
- A word-addressable memory of 2^20 words of 4 bytes each needs only 20 address bits, even though it holds 4 MB.
Byte order
Endianness is the order in which the bytes of a multi-byte value are stored. In a big-endian machine the most significant byte has the lowest address. In a little-endian machine the least significant byte has the lowest address.
value = 0x12345678
print(value.to_bytes(4, "big").hex()) # 12345678
print(value.to_bytes(4, "little").hex()) # 78563412Each output lists the bytes from the lowest address upward. Both layouts are valid ISA choices. They matter when you exchange binary data between machines.
Alignment
An aligned access places an n-byte value at an address that is a multiple of n. Some ISAs require alignment and trap otherwise. Others allow misaligned access and pay a performance cost.
Seeing the format as bit fields
The instruction format is part of the ISA, so decoding is a matter of slicing bits. Here is a toy 16-bit ISA with a 4-bit opcode, a 4-bit register field and an 8-bit address field:
def decode(word):
"""Split a 16-bit instruction into (opcode, register, address)."""
opcode = (word >> 12) & 0xF
reg = (word >> 8) & 0xF
addr = word & 0xFF
return opcode, reg, addr
print(decode(0x1A2F)) # (1, 10, 47)Here 0x1A2F splits into opcode 0x1, register 0xA (10) and address 0x2F (47). The field widths limit the design. Four opcode bits allow at most 16 instructions, and eight address bits reach only 256 locations. Later chapters on formats and expanding opcodes build on this trade-off.
Common errors
- Mixing ISA and organization. "The control unit is microprogrammed" is an implementation fact. "The machine has a 32-bit register file" is an ISA fact. GATE questions often ask you to classify statements this way.
- Assuming word size equals address size. A 32-bit machine can have 64-bit addresses, and a 64-bit machine can have 48-bit physical addresses.
- Counting address bits from capacity without checking the unit. Divide by the addressable unit first. Bytes and words give different answers.
- Treating the PC as an ordinary register. It is architectural, but most instructions change it only by advancing it. Only control-flow instructions load it with a new target.
Exercises
Exercise
A machine has a 32-bit instruction word, 32 general registers and a 64 MB byte-addressable memory. One instruction format holds one register field and one direct memory address, with the rest of the bits for the opcode. How many bits remain for the opcode, and how many distinct opcodes does that allow?
Show answer
The 64 MB memory is 2^26 bytes, so the address field needs 26 bits. The 32 registers need 5 bits. That totals 31 bits, so 32 - 31 = 1 bit remains for the opcode. One bit allows 2 distinct opcodes.
Exercise
Which of these belong to the ISA, and which belong to the implementation? (a) number of visible registers, (b) depth of the pipeline, (c) little-endian byte order, (d) carry-lookahead adder.
Show answer
(a) and (c) belong to the ISA, because a program can observe them. (b) and (d) belong to the implementation, because a correct program gives the same results with any pipeline depth or adder type.