ALU ng pin question

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

ALU ng pin question

cholland89
This post was updated on .
The obvious way to detect a negative number would be to simply take the most significant bit, however having a 1 for the MSB does not necessarily indicate the number is negative right? For example:

0100000000000000 (16,384)+
0100000000000000 (16,384)
-------------------
1000000000000000 (32,768)

Are we to assume that we will be using signed ints and will absolutely not support positive ints above 32,767, or at least not without ignoring the ng pin? Just wondering since all of the other pins seem to be unambiguous.
Reply | Threaded
Open this post in threaded view
|

Re: ALU ng pin question

ybakos
What is the 16-bit value 1000000000000000 in a 2's complement binary system?

"Are we to assume that we will be using signed ints and will absolutely not support positive ints above 32,767"

That's right.

(If the 2's complement system is not something you are comfortable with, take a little time to investigate. It's simple once you grasp it.)
Reply | Threaded
Open this post in threaded view
|

Re: ALU ng pin question

cholland89
Thanks for the response. Indeed, I've reviewed the chapter's section on 2's complement, it was more helpful this time for some reason. I'll await the sections on software to see if HACK allows the use of unsigned ints.

"What is the 16-bit value 1000000000000000 in a 2's complement binary system? "

-32768

Once again, thank you very much for you prompt and helpful response.
Reply | Threaded
Open this post in threaded view
|

Re: ALU ng pin question

cadet1620
Administrator
cholland89 wrote
0100000000000000 (16,384)+
0100000000000000 (16,384)
----------------
1000000000000000 (32,768)
cholland89 wrote
I'll await the sections on software to see if HACK allows the use of unsigned ints.
The Hack computer and its software are designed around signed integers; there is no provision for unsigned integers in the Virtual Machine nor in the Jack language.

The supplied tests carefully avoid signed integer overflows, which can be quite tricky to handle in software.

You have shown that something as simple as x=abs(y) can cause an overflow if y=-32768.

--Mark