NivaarExam PrepOfficial exam papers ↗

25-Comp-A3 Computer Architecture · May 2017

Question 2 of 6: Opcode Space and Register-Field Width in a Fixed 32-bit Instruction Encoding

Nivaar worked solution (AI-drafted; not reviewed by a licensed engineer)

Notes on this paper

98-Comp-A3, Computer Architecture — National Exams, May 2017. Open-book, 3 hours; six questions of equal value (20 marks each); FIVE constitute a complete exam (all six answered below as a complete study resource).

Reference texts: Patterson & Hennessy, Computer Organization and Design, 6th ed. — number representation and IEEE-754 floating point (Q1a–b), memory addressing and array layout (Q1c–d), instruction encoding and RISC field allocation (Q2), memory-system performance (Q3a), programmed vs. interrupt-driven I/O (Q3b), cache organization and set-associative indexing (Q4), memory-chip capacity and composition (Q5), and multi-cycle datapath performance and cache history (Q6).

Question 2: Opcode Space and Register-Field Width in a Fixed 32-bit Instruction Encoding (20 marks)

Question text not reproduced: the examination questions are © Engineers and Geoscientists BC. Open the official past paper (linked at the top of this page) to read the question, then follow the worked solution below.

Given. 32 GPRs (5-bit register numbers), a 4-bit opcode field shared by every instruction, Format R (opcode 4 + dest 5 + src1 5 + src2 5 + 13 unused = 32 bits, used by opcodes 0x0–0x9) and Format I (opcode 4 + dest 5 + src 5 + immediate 18 = 32 bits, used by 0xA–0xE).

Find. (a) Whether new instructions can be added, how many, and a Format-R-style (1 dest, 2 src) example. (b) Whether the register file can grow to 64 registers within the fixed 32-bit encoding, and the maximum total register count achievable for a 1-dest/2-src instruction with any register combination.

Approach. The opcode field is only 4 bits, so it caps the total number of distinct instructions regardless of format; register-field width caps the register count for a given instruction shape, and any unused bits in the current layout are the only budget available to widen those fields without exceeding 32 bits total.

  1. Part (a) — opcode space and adding an instruction. The opcode field is 4 bits wide, so it can distinguish $2^4=16$ distinct instructions in total. Opcodes 0x0–0x9 (10 values, Format R) and 0xA–0xE (5 values, Format I) are already assigned, using $10+5=15$ of the 16 possible codes, leaving exactly $16-15=\boxed{1}$ free opcode: 0xF. Since a free opcode exists, YES, one more instruction can be introduced. An instruction with 1 destination and 2 source registers is exactly the shape Format R already encodes (opcode 4 + dest 5 + src1 5 + src2 5, with 13 bits still unused), so it can be added directly under the free opcode without inventing a new layout, e.g.: $$\texttt{0xF | Rd(5) | Rs1(5) | Rs2(5) | unused(13)}\quad\Rightarrow\quad \text{XOR}\ R4,\ R5,\ R6$$ Because that free opcode is the ONLY remaining code in the 4-bit space (all $16$ are now used: $10+5+1$), $\boxed{0\text{ further instructions of this or any type}}$ can be added afterward without widening the opcode field itself.
  2. Part (b) — widening the register file to 64 registers. Representing 64 distinct registers needs $\lceil\log_2 64\rceil=6$ bits per register field (up from 5). Using the existing Format R layout with 6-bit register fields: opcode $4$ + dest $6$ + src1 $6$ + src2 $6 = 22$ bits, leaving $32-22=10$ bits unused — still non-negative, so YES this fits, e.g. reusing an existing opcode (say 0x0, ADD) with widened fields: $$\texttt{0x0 | Rd(6) | Rs1(6) | Rs2(6) | unused(10)}\quad\Rightarrow\quad \text{ADD}\ R37,\ R5,\ R61\ \ (0\le R\le 63)$$ Maximum total registers: the 13 bits that Format R currently leaves unused are the only budget available to widen the three register fields (dest, src1, src2) uniformly. Adding $x$ extra bits to each of the 3 fields consumes $3x$ of those 13 spare bits, so the largest integer $x$ with $3x\le13$ is $x=4$ (using 12 of the 13 spare bits, 1 left over), giving a register-field width of $5+4=\boxed{9\text{ bits}}$ and therefore up to $2^9=\boxed{512\text{ registers}}$ — verified by the full bit budget: $4\ (\text{opcode})+3\times9\ (\text{registers})+1\ (\text{still-unused}) = 32$.
Final results — Question 2
PartResult
(a) free opcodes / new instructions$\boxed{1}$ free opcode (0xF); after using it, $\boxed{0}$ more can be added
(b) 64-register feasibilityFeasible — needs 6-bit register fields (22 of 32 bits used, 10 spare)
(b) max total registers (1 dest, 2 src, any combination)$\boxed{512}$ registers (9-bit register fields)
Format R (opcode 0x0–0x9) Opcode Dest Reg Src Reg 1 Src Reg 2 unused 4 5 5 5 13 Format I (opcode 0xA–0xE) Opcode Dest Reg Src Reg Immediate 4 5 5 18
Fig. Q2 — the two fixed 32-bit instruction formats, field widths in bits. The 4-bit Opcode field (16 codes) is the binding constraint on how many instructions can exist; the three register fields in Format R are the binding constraint on how many registers a 3-operand instruction can address.