Re: ALU Struggle
Posted by
bwspot on
Apr 18, 2014; 11:38pm
URL: http://nand2tetris-questions-and-answers-forum.52.s1.nabble.com/ALU-Struggle-tp4028020p4028022.html
cadet1620 wrote
bwspot wrote
...
For example, lets say input x is 1 and
zx and nx are 1
therefore if zx = 1 then x = 0 and if nx = 1 then x = !x
how x can be 0 and not !x at the same time?
my though process is to manipulate the input first based on nx zx ny zy bits and then do f an no bits.
Mostly correct. It's not the case that x is both 0 and !x; rather, it is x=0 THEN x=!x.
This is explained in the text in chapter 2:
For example, let us consider the twelfth row of figure 2.6, where the ALU is instructed to compute the function x-1. The zx and nx bits are 0, so the x input is neither zeroed nor negated. The zy and ny bits are 1, so the y input is first zeroed, and then negated bit-wise. Bit-wise negation of zero, (000 . . . 00), gives (111 . . . 11), the 2’s complement code of -1. Thus the ALU inputs end up being x and -1. Since the f-bit is 1, the selected operation is arithmetic addition, causing the ALU to calculate x+(-1). Finally, since the no bit is 0, the output is not negated but rather left as is. To conclude, the ALU ends up computing x-1, which was our goal.
--Mark
thx for clarification, somehow i missed that and created nonsense logic.
Now i just need to keep staring at the table until i get it.
My idea is to first make decisions based on zx , nx, zy, ny bits followed f an no.