1
$\begingroup$

Consider the following computation: 2^N (TWO TO THE POWER OF ‘N’, for Int. N>0), being executed on a processor with 32 bit internal, user and ALU registers. The registers rightmost bit is bit 0 and the leftmost bit(the sign) is bit 31. WHAT is the SMALLEST value of ‘N’ that will cause the Overflow Status Flag (V) to be set?

Seems like the calculation should be as simple as plugging values in for N but I don't quite understand if there are any other components to take into account, any help is appreciated.

$\endgroup$

1 Answer 1

1
$\begingroup$

You don't explain how $2^N$ is calculated, so I'm assuming you repeatedly multiply by 2 (or equivalently, you repeatedly add the number to itself, or shift it left). Here's how this process looks on a 4-bit signed register. You start with $0001$, the answer for $N=0$. Doubling it, we reach $0010$, the answer for $N=1$. Doubling again, we reach $0100$, the answer for $N=2$. Doubling again, overflow occurs (why?).

If the register was unsigned, we could double one more time, obtaining $1000$, the answer for $N=3$. Then we would overflow when doubling again (why?).

I believe you now have the tools to solve your own exercise. I won't verify your answer, so no point asking about it below.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.