GATE CSE 2023 Q41: Fill operands U1–U4 in assembly for a[i] = b[i] * 8
- Computer Organization and Architecture
- 2 marks
- MCQ
- −2/3 if wrong
Question
Consider the given C-code and its corresponding assembly code, with a few operands U1–U4 being unknown. Some useful information as well as the semantics of each unique assembly instruction is annotated as inline comments in the code. The memory is byte-addressable.
//C-code
int a[10], b[10], i;
// int is 32-bit
for (i=0; i<10;i++)
a[i] = b[i] * 8;
;assembly-code (; indicates comments)
;r1-r5 are 32-bit integer registers
;initialize r1=0, r2=10
;initialize r3, r4 with base address of a, b
L01: jeq r1, r2, end ;if(r1==r2) goto end
L02: lw r5, 0(r4) ;r5 <- Memory[r4+0]
L03: shl r5, r5, U1 ;r5 <- r5 << U1
L04: sw r5, 0(r3) ;Memory[r3+0] <- r5
L05: add r3, r3, U2 ;r3 <- r3+U2
L06: add r4, r4, U3
L07: add r1, r1, 1
L08: jmp U4 ;goto U4
L09: endWhich one of the following options is a CORRECT replacement for operands in the position (U1, U2, U3, U4) in the above assembly code?
Try it: multiple choice: exactly one correct option
Show answer and explanation
Answer: B (official GATE 2023 final answer key)
Concept used: Multiplying by is a left shift by ; array pointers advance by the element size in bytes.
First step: Write 8 as a power of 2 to get U1, and use the 4-byte int size for the pointer increments.
Full step-by-step solution
Detailed working, common mistakes and linked mock tests will be available with a free GATEiit account. Log-in is coming soon.
Share this question
Source: official GATE 2023 CS question paper and final answer key, organised by IIT Kanpur. Question paper · Answer key
More Computer Organization and Architecture PYQs
- 2026 Session 1 · Q14Match addressing modes with high-level data elements
- 2026 Session 1 · Q15Instruction sequence for Z = X + Y on a load-store machine
- 2026 Session 1 · Q16Register dependency that causes a data hazard
- 2026 Session 1 · Q36IEEE 754 single-precision sum of 35C00000 and 34A00000
- 2026 Session 1 · Q38Tag length: direct-mapped vs K-way set-associative cache
- 2026 Session 1 · Q54Impossible TLB / page table / cache event sequences