ALU 'ng' output confusing me

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

ALU 'ng' output confusing me

netanel
I can't understand why the msb of the output == ng?

Say I have a 4 bit ALU, and I added 0111 to 1000, the result would be 1111.
If my calculation was 7+8=15, the msb is 1, and ng is also 1, but 15 is not less than 0.

I understand that in 2's complement, 1111 is actually -1, so it is less than 0, but that would mean that the ng output is only useful if you already expect to treat the answer as 2's complement?

I couldn't find help in chapter 2 or the lecture. What am I missing here?
Reply | Threaded
Open this post in threaded view
|

Re: ALU 'ng' output confusing me

cadet1620
Administrator
As you said, numbers with the most significant bit set can be either a large positive number or a negative number depending on context.

In the Hack Computer, all numbers are assumed to be 16-bit 2's complement, so the MSB alone is enough to indicate a negative result.

A more sophisticated computer would have an ALU that would also have an overflow flag. Then you could tell the difference between an addition that resulted in a large positive number or a subtraction that resulted in a negative number.

--Mark