Question

Consider a processor with 64 registers and an instruction set of size twelve. Each instruction has five distinct fields, namely, opcode, two source register identifiers, one destination register identifier, and a twelve-bit immediate value. Each instruction must be stored in memory in a byte-aligned fashion. If a program has 100 instructions, the amount of memory (in bytes) consumed by the program text is ________.

Official answer and solution
Official answer
500
From
Official GATE 2016 answer key

Solution

Calculate the bits required for each field of the instruction word and round up to the nearest byte boundary.

Analyze the bit fields of each instruction:

  1. Opcode field: The instruction set has 12 distinct instructions.

    Opcode bits=⌈log⁡212⌉=4 bits(23<12≤24)\text{Opcode bits} = \lceil \log_2 12 \rceil = 4 \text{ bits} \quad (2^3 < 12 \le 2^4)
  2. Register identifier fields: The processor has 64 registers.

    Bits per register identifier=⌈log⁡264⌉=6 bits\text{Bits per register identifier} = \lceil \log_2 64 \rceil = 6 \text{ bits}

    There are 2 source registers and 1 destination register, giving 3 register fields:

    Total register bits=3×6=18 bits\text{Total register bits} = 3 \times 6 = 18 \text{ bits}
  3. Immediate value field: Given as 12 bits.

Total bits per instruction:

Total bits=4+18+12=34 bits\text{Total bits} = 4 + 18 + 12 = 34 \text{ bits}

Byte-alignment constraint: Each instruction must be stored in a byte-aligned fashion, meaning its memory footprint must be an integral multiple of 8 bits:

Bytes per instruction=⌈348⌉=⌈4.25⌉=5 bytes\text{Bytes per instruction} = \left\lceil \frac{34}{8} \right\rceil = \lceil 4.25 \rceil = 5 \text{ bytes}

For a program containing 100 instructions:

Total memory consumed=100×5=500 bytes\text{Total memory consumed} = 100 \times 5 = 500 \text{ bytes}
Final answer

500

Common trap

Computing (100×34)/8=425(100 \times 34) / 8 = 425 bytes without enforcing that each individual instruction must be byte-aligned.

The answer is the one in the official GATE answer key. The solution is this site's own explanation.

Source

Paper
GATE 2016 Computer Science and Information Technology (CS) Session 2
Question
41 of 65, printed as CS Q.31
Section
Computer Science and Information Technology

Report an error in this question

GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.