Instructions & Addressing Modes
![Question 41, GATE 2023: Translate for(i=0;i<10;i++) a[i]=b[i]*8, with 32-bit ints and byte addressing. r1=0,r2=10 and r3,r4 point to a,b. L01 tests r1==r2 and exits; L02 loads from r4; L03 shifts left by U1; L04 stores at r3; L05,L06 add U2,U3 to r3,r4; L07 increments r1; L08 jumps to U4. Find U1,U2,U3,U4.](../../assets/questions/CS-2023-Q41-1.webp)
Answer & solution
Official answer: B
Multiplication by 8 is a left shift by 3, so U1=3. A32-bit int occupies 4 bytes in the stated byte-addressed memory, so both source and destination pointers advance 4: U2=U3=4. Each iteration must revisit the termination test at L01, making U4=L01. Answer B, under the usual arithmetic range assumptions for this translation.
Teaching detail. The loop counter r1 counts elements, so its increment is one; the address registers count bytes, so their increments differ. Shifting by 3 multiplies a representable nonnegative binary value by 2³, whereas shifting by 8 would multiply by 256. A jump to L02 would skip the test on later iterations and make termination incorrect. Translating signed C shifts or overflow in full generality requires care, but the intended machine-code comparison is element addressing and multiplication by a power of two within the assumed range.