in CO and Architecture edited by
393 views
4 votes
4 votes

Your code is required to perform the function $(\text{M}\%16) \ast 3.$ What should you do to eliminate multiplication ($\ast$) and mod($\%$), assuming $\mathrm{M}$ is $32$ bits wide?

  1. shift $\text{M}$ right by $4,$ shift left by $1,$ and add current value to itself.
  2. shift $\mathrm{M}$ right by $4,$ save the result to register, and add the saved result to current result twice.
  3. AND $\mathrm{M}$ with $0000000 \mathrm{Fh}$, save the result to register, and add the saved result to current result twice.
  4. AND $\mathrm{M}$ with $0000000 \mathrm{Fh}$, save the result, shift result left by $2,$ and add the saved result to current result.
in CO and Architecture edited by
393 views

3 Comments

when the question needs % Mod to be eliminated, why does it mention division? isn't it a classic example of ambiguity and illy formed question

Consider Correct answers as both B or C.

3
3

@Mahanth Yalla i also think the same whom to follow either to follow word means “divison “” or to sign “%” 
there is a confusion

1
1

@Mahanth Yalla, @Ashfaque alam, the question should have mentioned “mod” instead of “division”. The question was taken from a standard resource (Q 19 here) and the ambiguity came with it. Now we have corrected it & made it unambiguous.

Option $B$ would be correct if it was division instead of mod. 

So, answer has been changed to $B$ or $C.$ 

1
1

1 Answer

4 votes
4 votes

For any number $\mathrm{Y}$ in binary, Calculating $\mathrm{Y} \bmod 2^n$ is equivalent to stripping off all but the $\mathrm{n}$ lowest-order (right-most) bits of number $\mathrm{Y}$.

So in other words, if $\mathrm{Y}$ is $8$-bits number then $\mathrm{Y}$ mod $4$ is the same as $\mathrm{Y} \& 00000011$ (where $\&$ means bitwise-and)

Note that this works exactly the same in base-$10: \text{Y} \mod 10$ gives you the last digit of the number $\mathrm{Y}$ in base-$10, \mathrm{Y} \mod 100$ gives you the last two digits, etc.

So, If $\mathrm{M}$ is $32$ -bits number then $\mathrm{M} \mod 16$ is the same as $\mathrm{Y} \& 0000000 \mathrm{~F}$ (where $\&$ means bitwise-and)

Option C is the correct approach. The bitwise AND operation with $\textsf{0000000Fh}$ extracts the lowest $4$ bits of $\mathrm{M}$, and then the result is multiplied by $3$ by adding it to itself twice.


The question initially had ambiguity. It should have mentioned “mod” instead of “division”. The question was taken from a standard resource (Q 19 here) and the ambiguity came with it. Now we have corrected it & made it unambiguous.

Option $B$ would be correct if it was division instead of mod. 

So, answer has been changed to $B$ or $C.$ 

edited by

1 comment

edited by
.
0
0
Answer:

Related questions