Question:medium

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. 

Show Hint

Array index steps in byte-addressable memory depend on element size: for 32-bit int}, add $4$ each iteration. Multiplying by $2^k$ is just a left shift by $k$.
Updated On: Feb 3, 2026
  • $(8,\,4,\,1,\,\text{L02})$
  • $(3,\,4,\,4,\,\text{L01})$
  • $(8,\,1,\,1,\,\text{L02})$
  • $(3,\,1,\,1,\,\text{L01})$
Show Solution

The Correct Option is B

Solution and Explanation

To determine the values of the unknown operands U1, U2, U3, and U4 from the given C and assembly codes, let us analyze them step-by-step.

Given C code: 

The C code performs operations on arrays a and b. For a loop iterating over index i, it assigns a[i] the value of b[i] * 8.

Analysis of assembly code:

  1. L01: jeq r1, r2, end - Checks if r1 (initial value 0) equals r2 (value 10). If yes, it jumps to end. Since initially they're not equal, the loop continues.
  2. L02: lw r5, 0(r4) - Load word: r5 = b[i] (since r4 holds the base address of b).
  3. L03: shl r5, r5, U1 - Shift left the content of r5 by U1 bits. To achieve the multiplication by 8 (equivalent to b[i] << 3), U1 must be 3.
  4. L04: sw r5, 0(r3) - Store word: Store the result in a[i] (since r3 holds the base address of a).
  5. L05: add r3, r3, U2 - Increment the base address for array a. Since each integer is 4 bytes, U2 is 4.
  6. L06: add r4, r4, U3 - Increment the base address for array b. Similarly, U3 is also 4.
  7. L07: add r1, r1, 1 - Increment index i.
  8. L08: jmp U4 - Jump back to continue the loop. The logical position to return is L01 where the loop condition is checked, so U4 is L01.

Based on this analysis, the operands are deduced as:

  • U1 = 3: For the shift left operation to result in multiplication by 8.
  • U2 = 4: For incrementing the address to the next integer in a.
  • U3 = 4: For incrementing the address to the next integer in b.
  • U4 = L01: To jump back to the start of the loop.

Conclusion: The correct set of operands is $(3,\,4,\,4,\,\text{L01})$.

Was this answer helpful?
0