Instruction Set Architecture (ISA)

an instruction format

An instruction format is the fixed blueprint that says which bits of an instruction mean what. To the processor an instruction is just a string of bits — for example 32 ones and zeros. The format is the agreed-upon way to chop that string into labeled fields, exactly like a paper form with boxes: this box is the surname, that box is the date. Without the format the bits are meaningless; with it, the hardware knows that these bits are the operation, those bits name a register, and the rest is a number.

RISC-V has a small set of formats so that decoding stays simple. The R-type format (register-to-register arithmetic) splits its 32 bits into fields: an opcode plus extra function bits to say which operation, two source-register numbers, and one destination-register number. The I-type format (used by loads and add-immediate) replaces one source register with a 12-bit immediate constant. There are also formats for stores and branches that pack the immediate differently. Crucially, the register-number fields sit in the same bit positions across formats, so the hardware can start reading register numbers before it has even finished figuring out the exact operation.

The whole point of a regular, fixed-length format is speed and simplicity. If every instruction is the same width and the fields line up, the chip can find the opcode and register numbers instantly, with no guessing about where the next instruction starts. This is a core reason RISC designs pipeline so cleanly. The trade-off is that fixed 32-bit instructions can waste space and limit how big an immediate you can carry — which is exactly the tension CISC designs resolve differently with variable-length instructions.

A RISC-V R-type instruction like 'add' lays its 32 bits out as: [function7 | rs2 | rs1 | function3 | rd | opcode]. The opcode and function bits together pick 'add'; rs1 and rs2 name the two inputs; rd names where the result goes.

Same fields in the same places across formats is what makes fixed-length decoding fast.

Fixed-length is a RISC choice, not a law of nature. CISC ISAs like x86 use variable-length instructions (1 to 15 bytes) to pack more meaning per instruction — denser code, but harder and slower to decode.

Also called
instruction encodinginstruction layout指令編碼指令格式