Here's the deal:
I finally made an ALU and came to the point of testing it with the .tst script.
Thing is, i got a comparison failure at line 3, so i went out to check the .out file and compare it to the .cmp and i can see where the error comes from. However, i don't understand why i am the one who's wrong:
Why does this line outputs 1?
| x | y |zx |nx |zy |ny | f |no | out |zr |ng |
| 0000000000000000 | 1111111111111111 | 1 | 1 | 1 | 1 | 1 | 1 | 0000000000000001 | 0 | 0 |
my brain's sure all mushy but how come x and y set to zero then negated then 2's complement added then negated can output 0000000000000001 ?
I'm a bit lost there, thanks in advance for any help.
Thanks for your quick reply.
Does this mean that negation turns 0s in 1s and 1s in 0s?
EDIT: I guess the answer's yes, cause i fixed the problem. Actually i was trying to turn (for example) 42 in -42, while i should only have turn 0s in 1s and vice versa.
Comparison now ends successfully !
As you move forward, you'll find that there are at least 3 different types of "negation" used in the N2T course: bitwise, arithmetic and logical.
Bitwise negation inverts each bit in value individually.
Arithmetic negation does 2's-complement.
Logical negation in the Jack language converts true to false and vice-versa.
C/C++ has 3 different operators to support these, too: '~', '-' and '!'.