GATE / CS ARCHIVE

SIMILAR QUESTIONS / COMPUTER ORGANIZATION & ARCHITECTURE

Allocate bits to fixed-width instruction fields

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

How these are solved

Use ceiling logarithms for opcode/register/mode choices, subtract all explicitly present fields from instruction width, and convert the residual to immediate range, opcode count, unused bits or byte-aligned program storage as requested.

2 marks · MCQ
Report issue

Allocating bits in an instruction format

Instructions & Addressing Modes

Question 37, GATE 2025: A processor has 64 general-purpose registers, 50 instruction types, and fixed 32-bit instructions. For ADD R1,#25, meaning R1=R1+25, what is the maximum immediate field width in the conventional fixed-width opcode/register-field model? A 16; B 20; C 22; D 24 bits.
Tap to enlarge
Your answer
Answer & solution

Official answer: B

Approach: Reserve the minimum bits needed for the opcode and the explicitly encoded register, then assign the remainder to the immediate.
There must be at least 50 opcode patterns. Five bits provide only 32 patterns, while six provide 64, so the opcode requires ceil(log₂50)=6 bits. Selecting among 64 registers requires log₂64=6 bits.
This two-address instruction uses R1 both as a source and as the destination; the same register is encoded once, not in two independent fields. Thus the immediate can occupy 32−6−6=20 bits, option B.
The calculation assumes a uniform opcode field and no additional mode or reserved fields, as intended by the question. A 16-bit immediate would leave unused capacity under those assumptions, while 22 or 24 bits would not leave enough room for both required fields. An instruction-set design with variable-length opcodes would need additional specification before such a maximum could be established.

Original paper, page 37 · Answer key

2 marks · NAT
Report issue

Allocate fixed-width instruction fields

Instructions & Addressing Modes

Question 57, GATE 2024: A 32-bit instruction contains opcode, addressing-mode field, two register operands, and a 16-bit scalar. The processor has 16 general-purpose registers and 8 addressing modes. What maximum number of opcodes is possible for each mode?
Tap to enlarge
Answer & solution

Official answer: 32

Approach: Reserve enough binary codes for each independent fixed-width field, then count the remaining opcode patterns.

1. Derivation. Each of 16 registers requires 4 bits, so the two register fields use 8 bits. Eight addressing modes require 3 bits and the scalar field uses 16. The opcode therefore has 32−8−3−16=5 bits, supporting 2⁵=32 unique opcodes for each mode under the separate fixed-field format.

2. Explanation and checks. A register identifier uses ceil(log2 16)=4 bits even though an operand value may occupy many more bits. The two fields therefore cost eight bits, not sixteen or thirty-two. The mode field needs ceil(log2 8)=3 bits. After allocating these and the scalar there are five opcode bits. The question asks per addressing mode, so the eight mode patterns are not multiplied into the number of distinct opcode-field encodings.

Original paper, page 37 · Answer key

2 marks · NAT
Report issue

Account for a type tag and register fields

Instructions & Addressing Modes

Question 61, GATE 2024: A 32-bit ISA has 150 instructions, 75 each of R-type and I-type, and 50 registers. OPCODE includes a 1-bit type tag plus operation bits. R-type fields: OPCODE, UNUSED, DST, SRC1, SRC2. I-type: OPCODE, DST, SRC, immediate/address. Equal-sized register fields are used. If UNUSED, OPCODE and immediate/address sizes are X,Y,Z, find X+2Y+Z.
Tap to enlarge
Answer & solution

Official answer: 34

Approach: Count the operation bits within each type, add the type bit, then subtract register fields from each format.

1. Derivation. There are 75 operations per instruction type, requiring 7 operation bits plus the 1-bit type tag, so Y=8. Each of 50 architectural registers requires 6 bits. The R-type unused field has X=32−8−3×6=6 bits; the I-type immediate field has Z=32−8−2×6=12 bits. Hence X+2Y+Z=6+16+12=34.

2. Explanation and checks. Six bits encode only 64 operations, insufficient for 75, so seven operation bits are necessary. The one-bit type discriminator brings the full opcode width to eight. Similarly five register bits encode only 32 names, while six accommodate 50. The R-type equation is X+Y+18=32 and the I-type equation is Y+12+Z=32. Adding those equations directly gives X+2Y+Z=64−30=34, which independently checks the field-by-field calculation.

Original paper, page 39 · Answer key

1 mark · NAT
Report issue

Instructions & Addressing Modes

Question 10, GATE 2016: A processor has 40 instructions and 24 general-purpose registers. Its 32-bit instruction has an opcode, two register fields and an immediate field. How many bits remain for the immediate?
Tap to enlarge
Answer & solution

Official answer: 16.0 : 16.0

Our answer: 16

Forty opcodes require ceil(log₂40)=6 bits. Each of 24 registers requires 5 bits, so two register fields need 10. The immediate field has 32−6−10=16 bits.

An r-bit identifier distinguishes at most 2r possibilities. Five opcode bits cover only 32 instructions, so six are needed; four register bits cover only 16 registers, so five are needed per operand. Some encodings remain unused, but fractional bit fields are impossible in this fixed-field format.

Original paper, page 27 · Answer key

2 marks · NAT
Report issue

Instructions & Addressing Modes

Question 31, GATE 2016: A machine has 64 registers and 12 instructions. Each instruction has opcode, two source registers, one destination register, and a 12-bit immediate. Instructions must be individually byte aligned. Find bytes used by 100 instructions.
Tap to enlarge
Answer & solution

Official answer: 500.0 : 500.0

Our answer: 500

Twelve opcodes need 4 bits; each of three register identifiers needs 6 bits for 64 registers; immediate uses 12. Total 34 bits per instruction. Byte alignment requires ceiling(34/8)=5 bytes per instruction, so 100 instructions occupy 500 bytes.

The bit fields require 4+6+6+6+12=34 bits. Individually byte-aligned storage rounds each instruction up to 40 bits, leaving six padding bits per instruction. Rounding only the aggregate 3400 bits would give 425 bytes but pack subsequent instructions at nonbyte boundaries, contrary to the stated alignment rule.

Original paper, page 33 · Answer key

1 mark · NAT
Report issue

Instructions & Addressing Modes

Question 9, GATE 2014: A machine uses 32-bit words and one-word instructions. It has 64 registers, each 32 bits long. There are 45 instructions, each containing an unsigned immediate and two register operands. Find the largest representable immediate.
Tap to enlarge
Answer & solution

Official answer: 16383

1. Method and setup. Encoding 45 instruction choices needs six bits, since five bits distinguish only 32 choices. Each register identifier also needs six bits; the physical width of a register does not determine the width of its identifier. Allocate opcode and register fields first, then use all remaining bits for the immediate.

2. Work through the result and its assumptions. The opcode needs ceil(log₂45)=6 bits and each of two register fields needs log₂64=6 bits. The32-bit word leaves 32−6−12=14 immediate bits, whose unsigned maximum is 2¹⁴−1=16383.

Original paper, page 9 · Answer key