5.1.4 · D5Instruction Set Architecture (ISA)

Question bank — Register file organization

1,493 words7 min readBack to topic

For the machinery behind the answers, lean on Multiplexers and Decoders (how reads and writes are selected), Datapath and ALU (why ports exist at all), and Pipeline Hazards (read-during-write timing).


True or false — justify

Recall A register file with 32 registers always needs a 5-bit address field.

True — selecting 1 of registers needs exactly == bits==. Fewer bits can't name every register; more bits waste opcode space. ::: True. is the minimum select width for the MUX and decoder; anything less leaves some registers unreachable.

Recall Doubling the number of read ports doubles the register file's area.

::: False. Area scales as , not linearly — extra ports add wires and stretch every cell in both dimensions, so cost grows super-linearly, not proportionally.

Recall Adding registers is free as long as you have spare opcode bits.

::: False. More registers widen the address field in every instruction, enlarge the read MUX and write decoder (slowing access), and add state to save on every context switch — it is costly on several fronts at once.

Recall Writing to R0 in RISC-V corrupts whatever constant it was holding.

::: False. R0 holds no state to corrupt — it is hardwired to 0 and writes are silently discarded, so add r0, r0, r0 is a safe nop.

Recall A register file storing 32 registers of 64 bits contains exactly 2048 flip-flops.

::: True for the stored bits: . Ports add wiring and MUX/decoder logic but not stored state, so the flip-flop count is unaffected by or .

Recall Two read ports means the file can read two

different registers each cycle. ::: True — each read port is an independent -to-1 MUX with its own select lines, so the two ports can address the same register or two different ones, freely.

Recall A single-write-port file can never update two registers in the same cycle.

::: True. One write port = one decoder routing data to exactly one register per clock edge; two simultaneous writes need , which is why superscalar cores add write ports.


Spot the error

Recall "To read

rs1 and rs2 we route both through the same multiplexer, one after the other." ::: Error: a single MUX outputs one value per select. Simultaneous reads need two independent MUXes (one per read port); serializing them would take two cycles and defeat single-cycle operand fetch.

Recall "The write decoder alone decides which register captures new data."

::: Error: the decoder picks the line, but each decoded line is ANDed with a global WriteEnable. Without the enable being asserted, no register captures — so writes happen only when both the address decodes and the enable is high.

Recall "Going from a 2-read/1-write file to a 4-read/2-write file makes it 2× larger."

::: Error: it's larger, not 2×. The port count enters squared, so the "obvious" doubling drastically underestimates the real area growth.

Recall "R0 wastes a flip-flop that could store useful data."

::: Error: R0 has no flip-flop — its read line is tied to logic 0. It costs zero storage while buying free mov, nop, and a constant-0 source, so it's a saving, not a waste.

Recall "Reads are built from decoders and writes from multiplexers."

::: Error: it's the reverse. Reading is pick one of many onto a wire → a MUX; writing is route one wire to one of many → a decoder + enable.

Recall "Because ports are just wires, a 10-read-port file is fine — it's only slightly bigger."

::: Error: each added port grows every cell's area and parasitic capacitance, so the whole file gets bigger and slower on every access. The law makes 10 ports enormous — real designs bank or split the file instead.


Why questions

Recall Why is

the natural default rather than some other split? ::: A 2-operand instruction like add rd, rs1, rs2 reads two sources and writes one destination in a single cycle. The port count is chosen to match the ALU's operand shape, not picked arbitrarily.

Recall Why does the area cost square the port count instead of just summing it?

::: One factor of is the number of wires crossing each cell; the other is that adding a port stretches each cell in both height and width (word-lines and bit-lines grow). Multiplying the two dimensions gives the square.

Recall Why do wide superscalar CPUs often split the register file into banks?

::: A monolithic file with many ports pays the penalty in full. Splitting into banks each with fewer ports keeps each bank cheap and fast, trading a routing/arbitration cost for a much smaller area explosion.

Recall Why does hardwiring one register to zero

save opcode space? ::: A constant-0 source lets several operations reuse the existing ALU: mov rd, rs becomes add rd, rs, r0, nop becomes add r0, r0, r0. Fewer dedicated opcodes are needed because one free constant collapses them into add.

Recall Why can't we just keep adding registers to eliminate memory accesses entirely?

::: Each register needs a wider address field everywhere, a bigger/slower MUX and decoder, and more state to save on calls and context switches. Past ~16–32 the encoding and speed costs outweigh the reduction in memory traffic.

Recall Why does the number of stored bits depend on

and but not on or ? ::: State lives in the flip-flops: registers × bits each. Ports are read/write access paths (wiring, MUXes, decoders) laid over that state — they change area and speed, never the amount stored.


Edge cases

Recall What value does a read port return when it reads the same register being written in that cycle?

::: It depends on the design: write-first (internal forwarding) returns the new value, read-first returns the old value. Pipelines add a bypass MUX so dependent instructions get the just-computed value and avoid a stale-data hazard.

Recall What happens if two write ports target the

same register in one cycle? ::: This is a write conflict — the outcome is undefined unless the design specifies priority. Hardware must either forbid it (via issue logic) or pick a fixed winner, since a flip-flop can capture only one value per edge.

Recall What is the minimum address width for a file with just 1 register?

::: bits — there's nothing to select, so no address field is needed. This is the degenerate boundary of the rule.

Recall If a register count

is not a power of two (say 20), how many address bits are needed? ::: bits, since 4 bits only reach 16. The remaining addresses are simply unused/reserved, which is why is usually chosen as a power of two.

Recall What does a read of R0 return immediately after you "wrote" a nonzero value to it?

::: Still 0. The write to R0 is discarded by construction, so R0 is always a reliable constant-0 source regardless of any preceding write instruction.

Recall With

(zero write ports), what kind of "register file" do you have? ::: A read-only constant table — you can select and read values but never update them. It's a degenerate case: useful for hardwired constants or lookup tables, not for general-purpose working registers.


Connections

  • Register file organization — the parent note these traps stress-test.
  • Multiplexers and Decoders — why reads use MUXes and writes use decoders.
  • Datapath and ALU — why the port count mirrors the ALU's operand shape.
  • Pipeline Hazards — the read-during-write and write-conflict edge cases.
  • RISC vs CISC — how register count trades against instruction encoding.