GATE / CS ARCHIVE

SIMILAR QUESTIONS / COMPUTER ORGANIZATION & ARCHITECTURE

Allocate remaining variable-length opcode space

3 questions solved the same way, newest first. Back to Computer Organization & Architecture

How these are solved

Determine operand-bit widths for each instruction class, count code-space consumed by its known operations, then allocate remaining distinguishable prefixes to the target class. This is expanding opcode allocation, not independent fixed-field subtraction.

2 marks · MCQ
Report issue

Allocating variable-length opcodes

Instructions & Addressing Modes

Question 44, GATE 2026: Instructions are 16 bits and there are 16 registers. An M instruction has two register operands plus a 6-bit immediate; R has three register operands; C has one register plus a 6-bit offset. Given 2 M opcodes and 7 R opcodes, maximize C opcodes. Options: A 8; B 4; C 64; D 16.
Tap to enlarge
Your answer
Answer & solution

Official answer: B

Givens and goal

Instructions are 16 bits and there are 16 registers. An M instruction has two register operands plus a 6-bit immediate; R has three register operands; C has one register plus a 6-bit offset. Given 2 M opcodes and 7 R opcodes, maximize C opcodes. Options: A 8; B 4; C 64; D 16.

Approach

Count occupied instruction encodings, then show the remaining space can be decoded unambiguously.

Step-by-step solution

1. Each register field needs log₂16=4 bits. M operands use 4+4+6=14 bits, leaving a 2-bit opcode. Each M opcode covers 2¹⁴ instruction words; two cover 2¹⁵, half of all 2¹⁶ words.
2. R operands use 12 bits, leaving a 4-bit opcode. Seven R opcodes cover 7×2¹²=28672 words, or 7/16 of the full space. M and R together occupy 1/2+7/16=15/16.
3. C operands use 4+6=10 bits, leaving a 6-bit opcode. Each C opcode covers 2¹⁰ words. The remaining capacity is (1/16)×2¹⁶=4096 words, so at most 4096/1024=4 C opcodes fit.
4. This upper bound is achievable with prefixes: use 00 and 01 for M. Of the eight remaining length-four prefixes 1000 through 1111, reserve seven for R. Extend the last prefix 1111 by 00,01,10,11 for four six-bit C opcodes.
5. No instruction format’s opcode is a prefix of another assigned opcode in this construction. Therefore four is both feasible and maximal, giving B. Simply observing that six bits permit 64 values ignores the already occupied encoding space.

Original paper, page 30 · Answer key

2 marks · NAT
Report issue

Instructions & Addressing Modes

Question 44, GATE 2020: A processor has 64 registers and 16-bit instructions. I-type has opcode, one register and a 4-bit immediate; R-type has opcode and two registers. Given 8 I-type opcodes, what is the maximum number of distinct R-type opcodes?
Tap to enlarge
Answer & solution

Official answer: 14

Worked explanation

A register number occupies log2 64=6 bits. I-type operands occupy 6+4=10 bits, leaving a 6-bit opcode; R-type operands occupy 12 bits, leaving a 4-bit opcode. Their opcode spaces cannot be independently filled because every complete 16-bit word needs an unambiguous interpretation. Each chosen I opcode consumes 210 words, so eight consume 8192. R opcodes each need 212 distinct operand combinations; the 57344 words left permit 14. Constructively, use four-bit prefixes 0000 through 1101 for R instructions. Reserve 1110 and 1111, extending each by two bits to obtain the eight six-bit I opcodes. This proves attainability as well as the counting bound.

Derivation and answer

Each register field needs 6 bits. An I-type opcode leaves 10 operand bits, so 8 I-type opcodes reserve 8*210=8192 of the 65536 instruction words. An R-type opcode needs 12 operand bits, consuming 4096 words. The remaining 57344 words allow 57344/4096=14 R-type opcodes. Achievability: reserve two four-bit opcode prefixes for the eight six-bit I-opcodes and use the other 14 four-bit prefixes for R-type instructions.

Original paper, page 14 · Answer key

2 marks · NAT
Report issue

Expanding opcodes and register fields

Instructions & Addressing Modes

Question 51, GATE 2018: A 16-bit instruction set has 16 integer and 64 floating registers. Four type-1 instructions use 3 integer operands; eight type-2 use 2 floating operands; fourteen type-3 use 1 integer+1 floating; N type-4 use 1 floating. Find maximal N.
Tap to enlarge
Answer & solution

Official answer: 32

Method

An integer register needs 4 bits and a floating register 6 bits. Operand bits are therefore 12,12,10,6 for the four categories, leaving variable opcode widths 4,4,6,10. Counting complete instruction words avoids assigning incompatible fixed-length opcodes. Each opcode must reserve all combinations of its operands. After subtracting the first three categories from the 65536 available words, divide the remaining words by 64 per type-4 instruction. The prefix construction below verifies that this counting bound can actually be encoded.

Solution

There are 216 instruction encodings. A three-integer-register instruction uses 212 encodings, as does a two-floating-register instruction. Each mixed register instruction uses 210 encodings. The remaining space is 65536−4*4096−8*4096−14*1024=2048. Each type4 opcode needs 64 encodings, so N≤2048/64=32. This bound is achievable with expanding opcodes: allocate 12 four-bit prefixes to types 1/2; the remaining 4 prefixes yield 16 six-bit prefixes, 14 for type3, leaving 2 prefixes expandable to 32 ten-bit type4 opcodes.

Original paper, page 21 · Answer key