Description

The ISA is the contract between software and hardware: the instructions, registers, data types, addressing modes and memory model that a processor exposes. Different ISAs (x86, ARM, RISC-V) need different compilers/binaries, but one ISA can have many microarchitectures.

H&P describe an ISA along seven dimensions: class (stack, accumulator, register-memory, load-store), memory addressing (byte addressing, alignment), addressing modes (register, immediate, displacement, ...), operand types and sizes, operations, control flow, and encoding (fixed vs variable length).

CISC (e.g. x86)RISC (e.g. ARM, RISC-V, MIPS)
InstructionsComplex, multi-step, variable lengthSimple, fixed length, load-store
Code sizeSmallerLarger (more instructions)
HardwareComplex decodeSimple decode, easy pipelining
EnergyHistorically higherLower, hence ARM in phones
StrengthBackward compatibilitySpeed, simplicity, efficiency

Modern x86 CPUs translate CISC instructions into internal RISC-like micro-ops, so the gap is mostly in the front end.

RISC-V is an open-source ISA: free to implement, modular (base integer ISA plus optional extensions M, A, F, D, C, V), and well suited to teaching, research and embedded/custom silicon. Its ecosystem is younger than ARM/x86.

UNIX introduced multitasking and modular design, influencing Linux and macOS; RISC ideas grew up alongside it.

Key Formulas

CPU time = IC × CPI × T      (RISC lowers CPI, may raise IC; CISC the reverse)

RISC-V R-type encoding (32 bits):
  | funct7 (7) | rs2 (5) | rs1 (5) | funct3 (3) | rd (5) | opcode (7) |
FormatUseFields
Rregister-register ALUfunct7, rs2, rs1, funct3, rd, opcode
Iimmediates, loads, jalrimm[11:0], rs1, funct3, rd, opcode
Sstoresimm[11:5], rs2, rs1, funct3, imm[4:0], opcode
Bbranchesimm bits (scrambled), rs2, rs1, funct3, opcode
Ului, auipcimm[31:12], rd, opcode
Jjalimm (20 bits scrambled), rd, opcode

RISC-V registers: x0 is hard-wired to zero; x1 (ra) return address; x2 (sp) stack pointer; a0-a7 arguments/returns; t0-t6 temporaries; s0-s11 saved.

Steps

To translate C to RISC-V: (1) map variables to registers, (2) load operands from memory (only lw/ld touch memory for loads, sw/sd for stores), (3) compute with register-register instructions, (4) store results, (5) for if/else use branch + jump with labels.

To encode an R-type instruction: (1) look up opcode/funct3/funct7, (2) convert register numbers to 5-bit binary, (3) concatenate fields, (4) convert to hex.

Worked Example

A. Memory operand. C: A[8] = h + A[8]; with h in x21, base of A in x22, 4-byte words (offset = 8 × 4 = 32).

lw   x9, 32(x22)      # x9 = A[8]
add  x9, x21, x9      # x9 = h + A[8]
sw   x9, 32(x22)      # A[8] = x9

x86-64 equivalent (CISC can fold memory into the ALU op):

mov  eax, [rbx+32]    # rbx = base of A
add  eax, ecx         # ecx = h
mov  [rbx+32], eax

B. If/else. C: if (i == j) f = g + h; else f = g - h; with f,g,h,i,j in x19-x23.

      bne  x22, x23, Else
      add  x19, x20, x21
      beq  x0, x0, Exit      # unconditional jump (x0 == x0 always)
Else: sub  x19, x20, x21
Exit:

C. Encoding add x5, x6, x7. funct7 = 0000000, rs2 = x7 = 00111, rs1 = x6 = 00110, funct3 = 000, rd = x5 = 00101, opcode = 0110011. Bits: 0000000 00111 00110 000 00101 0110011 = 0x007302B3.

D. CISC vs RISC trade-off. Same 2 GHz clock. CISC: IC = 1.0 × 10⁶, CPI = 4 → 4.0 × 10⁶ cycles. RISC: IC = 1.5 × 10⁶, CPI = 1.2 → 1.8 × 10⁶ cycles. RISC is 4.0/1.8 ≈ 2.2× faster here despite 50% more instructions.

Python / Assembly

Decoding an R-type instruction in Python:

def decode_rtype(word):
    return dict(
        opcode = word & 0x7F,
        rd     = (word >> 7)  & 0x1F,
        funct3 = (word >> 12) & 0x7,
        rs1    = (word >> 15) & 0x1F,
        rs2    = (word >> 20) & 0x1F,
        funct7 = (word >> 25) & 0x7F,
    )

print(decode_rtype(0x007302B3))
# {'opcode': 51, 'rd': 5, 'funct3': 0, 'rs1': 6, 'rs2': 7, 'funct7': 0}

Notes

  • ISA vs microarchitecture: the ISA is what the programmer sees; pipelines, caches and out-of-order engines are how it is implemented.
  • Quick facts: key ISA components are instruction format, data types, addressing modes and registers.
  • RISC-V's open model is the main reason it appears in research and education; the software ecosystem is still maturing relative to ARM/x86.
  • "Backward compatibility" is the big CISC (x86) advantage: binaries from decades ago still run.

References: [HP6] Ch. 1 (1.3), Appendix A; [PH-RV] Ch. 2 and Appendix; [RV-Spec] Vol. I;