Login  Register

Re: ALU Implementation

Posted by WBahn on Jul 24, 2021; 11:53pm
URL: http://nand2tetris-questions-and-answers-forum.52.s1.nabble.com/ALU-Implementation-tp4036186p4036191.html

There are many ways to implement the logic and any logic that works is valid.

The authors are definitely trying to steer you toward a particular solution (or at least very close to one) both by the parts they have you build, the way they word the specification, and how they describe it in the text.

Forget about the ALU spec and let's focus on just a tiny piece of the puzzle.

You have two 16-bit signals, let's call them A and B.

You have a 1-bit control signal, called C.

Can you use one (just one) of the parts you have already built so that the output is A if the control signal is a 0 and it is B is the control signal is a 1?

What if the signal B is always 0 (i.e., all sixteen bits are always a 0)?

Now compare how this works to what the zx and zy control signals are supposed to do.

Now let's take another example in which you have a single 16-bit input. Can you think of a way to use one (just one) of the parts you have already built to generate a second signal that is always the bitwise opposite of the first signal?

Can you use another part (just one more) that you have already built to use a 1-bit control signal, called D, so that it outputs the original signal if D is a 0 and the bitwise-negated version of the original signal if D is a 1.

Now compare how this works to what the nx, ny, and no control signals are supposed to do.