ALU, negationx, y, add16 off by one?

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

ALU, negationx, y, add16 off by one?

rogerdodger91
So when im adding positive x, to positive y. And I negate either one and set f to 1. Is it right that the result is a number that is one less compared to the result i would have gotten if I used a negative sign instead of the negation bit?

I originally fixed this by incrementing the noty, and notx outputs then ran them through a multiplexor with the negation bits and the original noty and notx for the adder16 gate. However the script said this was wrong. When i took out my fix, it works?

Here is a mathematical example.

1500 + -(500) = 1000. <hard coding the negative.
1500 + 500, ny = 1 = 999.

Is this not right? And if so why not?  
Reply | Threaded
Open this post in threaded view
|

Re: ALU, negationx, y, add16 off by one?

ybakos
Can you clarify your question?

I assume you're working on the ALU. What feature are you trying to accomplish? Are you familiar with the 2's complement system?
Reply | Threaded
Open this post in threaded view
|

Re: ALU, negationx, y, add16 off by one?

milythael
In reply to this post by rogerdodger91
It seems as though you have a misapprehension about the twos
complement notation.  not x (where x is positive) is not equal to -x.
I think this might best be explored with 0.  Obviously,
mathematically, -0 = 0, however, in twos complement, not 0 = -1.

On Tue, Dec 6, 2011 at 10:48 AM, rogerdodger91 [via TECS Questions and
Answers Forum] <[hidden email]> wrote:
> So when im adding positive x, to positive y. And I negate either one and set
> f to 1. Is it right that the result is a number that is one less compared to
> the result i would have gotten if I used a negative sign instead of the
> negation bit?
Reply | Threaded
Open this post in threaded view
|

Re: ALU, negationx, y, add16 off by one?

cadet1620
Administrator
In reply to this post by rogerdodger91
There are two types of negation, arithmetic and logical. Read the description of the ALU carefully and make sure you understand what type of negation is required.

Note that just changing the sign bit of a number results in a wildly different number, not the arithmetic negation of the number. Example: 0x0000 (0), 0x8000 (-32768).

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

Re: ALU, negationx, y, add16 off by one?

rogerdodger91
What im asking is, If were for instance put in the y out = 1. And then the bit control for ny = 1. And im supposed to get -1. Because in this case im getting -2.

Can i send one of you my implementation so you guys can see what im saying?
Reply | Threaded
Open this post in threaded view
|

Re: ALU, negationx, y, add16 off by one?

rogerdodger91
I went ahead and sent mark my ALU. I commented out the "fix" that would make the addition of the ny and nx = logical. While keeping the binary implementation sound. I realize the binary and the "fix" i made are in fact two different number nows. If you could clarify on how "fixes" in my ALU sucks id be happy to hear your critique.
Reply | Threaded
Open this post in threaded view
|

Re: ALU, negationx, y, add16 off by one?

cadet1620
Administrator
I got your email and will look at your ALU and comment.  You might also want to check out this worksheet that will help you learn how the ALU operates.

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

Re: ALU, negationx, y, add16 off by one?

rogerdodger91
I have a working ALU.

I just now have two ALUs.

One that does an off by one subtraction and on that give you a true valid subtraction answer.. They both give the same AND bitwise results results. I understand twos complement. I know that since you cant have a +0, and -0 is the reason why my method might be wrong. I just want to know why we dont necessarily us my proposed fixed with in place of the other one.

Whats wrong with my ALU basically theoretically speaking.
Reply | Threaded
Open this post in threaded view
|

Re: ALU, negationx, y, add16 off by one?

cadet1620
Administrator
While rogerdodger91 was writing:
Whats wrong with my ALU basically theoretically speaking.
I emailed him:
The Hack ALU is a very clever design.  It's not obvious why you don't need to use 2's complement negation to do subtraction.  Here's why it works to use binary NOT.

First, the definition of 2's complement gives:
    -x = NOT(x) + 1
    -x - 1 = NOT(x)

The x-y op code for the ALU is
    zx=0 nx=1 zy=0 ny=0 f=1 no=1
so the output is:
    out = NOT( NOT(x) + y )
    out = NOT( (-x - 1) + y )
    out = NOT( y - x - 1 )
    out = -(y - x - 1) - 1
    out = -y + x + 1 - 1
    out = x - y
--Mark
Reply | Threaded
Open this post in threaded view
|

Re: ALU, negationx, y, add16 off by one?

rogerdodger91
I see where my error was. Basically when i used a negative number, and then tried to negate it with ny it was screwing it up.