Skip to content
Official PYQ · 2004

GATE CS 2004 Q63 — Machine Instructions and Addressing Modes

Explain with AI

Consider the following program segment for a hypothetical CPU having three user registers R1,R2R_1, R_2 and R3.R_3. InstructionOperation Instruction size(in words)MOV R_1,5000R_1←Memory[5000]2MOV R2,(R1)R2←Memory[(R_1)]1ADD R_2,R_3R2←R_2+R_31MOV 6000,R_2Memory[6000]←R_22HALTMachine Halts1\begin{array}{|l|l|c|} \hline \text{Instruction} & \text{Operation }& \text{Instruction size} \\&& \text{(in words)} \\ \hline \text{MOV $R\_1,5000$} & \text{$R\_1$} \leftarrow \text{Memory$[5000]$}& \text{$2$} \\ \hline\text{MOV $R2,(R1)$} & \text{$R2$} \leftarrow \text{Memory$[(R\_1)]$}& \text{$1$} \\ \hline \text{ADD $R\_2,R\_3$} & \text{$R2$} \leftarrow \text{$R\_2 + R\_3$} & \text{$1$} \\ \hline \text{MOV $6000,R\_2$} & \text{Memory$[6000]$} \leftarrow \text{$R\_2$} & \text{$2$} \\ \hline \text{HALT} & \text{Machine Halts} & \text{$1$} \\ \hline \end{array}Consider that the memory is byte addressable with size 3232 bits, and the program has been loaded starting from memory location 10001000 (decimal). If an interrupt occurs while the CPU has been halted after executing the HALT instruction, the return address (in decimal) saved in the stack will be

Choose one option
View worked solution

Answer: D

To find the return address saved in the stack, we need to determine the memory address of the instruction immediately following the HALT instruction.

1. Understand the Word Size

The memory is byte-addressable, and the word size is 32 bits=4 bytes32\text{ bits} = 4\text{ bytes}. Therefore, each word occupies 44 bytes of memory.

2. Calculate Memory Allocation for Each Instruction

The program starts at memory location 10001000 (decimal). We calculate the address range for each instruction based on its size in words:

  • Instruction 1: MOV R1, 5000
    • Size: 2 words=8 bytes2\text{ words} = 8\text{ bytes}
    • Address range: 10001000 to 10071007
  • Instruction 2: MOV R2, (R1)
    • Size: 1 word=4 bytes1\text{ word} = 4\text{ bytes}
    • Address range: 10081008 to 10111011
  • Instruction 3: ADD R2, R3
    • Size: 1 word=4 bytes1\text{ word} = 4\text{ bytes}
    • Address range: 10121012 to 10151015
  • Instruction 4: MOV 6000, R2
    • Size: 2 words=8 bytes2\text{ words} = 8\text{ bytes}
    • Address range: 10161016 to 10231023
  • Instruction 5: HALT
    • Size: 1 word=4 bytes1\text{ word} = 4\text{ bytes}
    • Address range: 10241024 to 10271027

3. Determine the Return Address

During the fetch phase of the HALT instruction (located at address 10241024), the Program Counter (PC\text{PC}) is automatically incremented to point to the next instruction address:

PC=1024+4=1028\text{PC} = 1024 + 4 = 1028

When an interrupt occurs after executing the HALT instruction, the CPU saves the current value of the PC\text{PC} onto the stack as the return address. Thus, the saved return address is 10281028.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Machine Instructions and Addressing Modes questions