edited by
7,113 views
9 votes
9 votes

Consider the given $\text{C}$-code and its corresponding assembly code, with a few operands $\text{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.

Which one of the following options is a $\text{CORRECT}$ replacement for operands in the position $\text{(U1, U2, U3, U4)}$ in the above assembly code?

  1. $(8,4,1, \text{L02)}$
  2. $(3,4,4, \text{L01)}$
  3. $(8,1,1, \text{L02)}$
  4. $(3,1,1, \text{L01)}$
edited by

1 Answer

9 votes
9 votes

To understand $u_1$, we must first find out what the register $r_5$ is storing.

If you check closely the line $L_{02}$, it’s fetching an element from array $b$ and storing it in $r_5$.

Line $L_{04}$ is storing the value present in $r_5$ to array $a$, so we’re definitely performing the multiplication by $8$ in $L_{03}$.

$L_{03}$ is a shift-left operator. To multiply by $8$, how many bits (in binary) do we need to shift to left? If you can find out that number, that would be the answer to $u_1$.

$L_{05}$ and $L_{06}$ are incrementing the values of registers $r_3$ and $r_5$ respectively to point to next element of $a$ and $b$ respectively. But by how much shall we increase it to make it point to next element?

Suppose at some point in time, $r_3$ is storing $1000$ in decimal and pointing to 2nd element of array $a$. Recall that each element is 4Bytes in size (given in question). Now, what is the address of 3rd element of array $a$, can you guess? Yes, it would be $1004$. Hence, $4$ must be added.

Note: Given memory is byte addressable. Each int takes $32 bit = 4B$, so we need to shift by 4 addresses.

$u_4$ should be the line to make the loop repeat. Note that if we make it $L_{02}$, the loop termination condition is skipped and would lead to infinite loop (or unless we got trapped due to accessing illegal memory).

The value of $u_1, u_2, u_3, u_4$ will be $3, 4, 4, L01$.


Option B is the right answer.

edited by
Answer:

Related questions

10 votes
10 votes
2 answers
2
13 votes
13 votes
4 answers
3