I am currently working through Nand2tetris for an university course and it's mostly straightforward. But the alu can do subtraction in a single step and I absolutely do not understand how this works.
opMinus = addition <> notX <> notOut
I couldn't find any explanation for this online. And the last step when trying to derive this myself looks like nonsense even though quickcheck says it is correct:
a - b
a + !b + 1 -- 2s complement
!!(a + !b + 1) -- double negation
!(!a + b) -- apparently this is correct and i have no clue why
The last step feels like it relies on something like
!(a+b) == !a + !b + 1
but I have no intuition why this works so an explanation would be very much appreciated. Thanks for reading!