ALU tests

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

ALU tests

mH
Hi everyone.

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.

H.
Reply | Threaded
Open this post in threaded view
|

Re: ALU tests

cadet1620
Administrator
There are multiple kinds of negation. Look at figure 2.6 carefully, the column headers use "!" not '-'.

Ybakos wrote a worksheet to help students learn how the ALU does its magic.

--Mark
mH
Reply | Threaded
Open this post in threaded view
|

Re: ALU tests

mH
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 !
Reply | Threaded
Open this post in threaded view
|

Re: ALU tests

cadet1620
Administrator
Glad you figured it out.

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 '!'.

--Mark
 
mH
Reply | Threaded
Open this post in threaded view
|

Re: ALU tests

mH
Many thanks to you.
I'm now moving to chapter 3, this course is really great.
Reply | Threaded
Open this post in threaded view
|

Re: ALU tests

AndyPro720
In reply to this post by mH
You missed out on the addition while implementing, all 11111 + 11111 will have the first bit as 0. A silly mistake, that took me long enough!