Login  Register

Re: Problem in 2's compliment

Posted by WBahn on May 29, 2021; 7:10pm
URL: http://nand2tetris-questions-and-answers-forum.52.s1.nabble.com/Problem-in-2-s-compliment-tp4036032p4036049.html

There's more than one way to take the additive inverse other than negating all of the bits and then adding one to the result.

The authors give you the way to do it with their ALU architecture.

Look at the ALU truth table in Figure 2.6. Do you see that it can generate -x, -y, x-y, and y-x?

All you need to do is configure the control signals as shown by that table.

You don't even need to understand why it does the magic it does, but it is worth the effort to do so.

The key is to note that the approach you are using is the following:

-x = ~x + 1

But this can be rewritten as

~x = -x - 1