Re: Getting started with ALU
Posted by
cadet1620 on
Feb 20, 2018; 8:18pm
URL: http://nand2tetris-questions-and-answers-forum.52.s1.nabble.com/Getting-started-with-ALU-tp4030218p4031784.html
Jack Draak wrote
...although my ALU now passes it's tests, I'd love to grok either the statement from the book (because apparently I don't) or what magic I've crafted that let's me do it differently that I've just described.
You correctly understand the second half of that statement, and that is what counts: -x = !x + 1. (I think of the first half as just a pencil and paper shortcut; I think that it would be hard to prove because the operations are dependent upon the position of the least significant 1 bit.)
As stated in its comments, the ALU uses bit-wise Boolean negation -- which is Not -- and the operation code for -x is 001111: zx, nx = 0, zy, ny, f, no = 1, which results in
-x = !(x + (-1) )
Here is a proof that shows that the above operation is identical to the standard definition of 2's-complement negation.
-x = !(x + (-1) ) Invert both sides and simplify
!(-x) = x - 1 Substitute x = -x
!(--x) = -x - 1 Simplify
!x = -x - 1 Add 1 to both sides
!x + 1 = -x
QED
--Mark