Hi. I am creating a visual diagram of the Hack ALU. Ive gotter pretty far. Im lost though when it comes to the output ng. Im not sure just exactly what a lesser than zero is. How do I connect 16 output and make a lesser than zero. Any suggestions?
I think based on two's complement that it depends on the bit six like 16. So if their was only two bit the first two 00, 01 would be positive and the other would be negative. I suppose it is just like flipping the values. 10 would be negetive two. And 11 would be negetive one.
Thanks for the hint. I understand. I'm going to try to make a cup that will divide amongs the bits. Seems a little challenging. For 16 almost seems impossible. Especially being one output. Maybe I can just divide it. Im am going to start there.
The value you are trying to determine the sign for is a sixteen bit number.
Every number that your ng output is for has exactly sixteen bits.
So, if I give you a 16-bit value, you should be able to look at it and immediately say whether or not ng should be HI or LO.
Look at that list of ten 16-bit numbers I posted. You should literally be able to walk down that entire list in under five second and say, "False, True, False, True, True, False, True, True, False, False," as the value for ng for each line in turn.
I have reproduced below a portion of Figure 2-1 from Chapter 2, Section 2.4 of The Elements of Computing Systems where the representation of signed numbers using the 2's complement method is explained. This chart is for 4-bit binary numbers.
Note that this list includes every possible signed 4-bit number. Examine the binary representation carefully. What do you notice about the most significant bit (the left-most bits) that relates to whether the number represented is negative or non-negative?
Create a similar table for 5-bit signed integers using 2's complement representation. Is the same fact still true?
What about for 8-bit numbers? Still true?
Is it also true for 16-bit signed numbers represented in 2's complement?
This is the direction that WBahn is trying to direct you. If you're still unsure, get a copy of the book and look at the next paragraphs after the figure above where the authors explicitly provide the answer.
Using the property that you have discovered about 2's complement representation, it should be relatively straightforward to figure out how to set the proper value of the ng flag bit based on the current output of the ALU.