I don't understand the ALU flags

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

I don't understand the ALU flags

HowDoICraftAgain?
I built the ALU and everything but I need 2 things, the 2 flags. zr: 1 if (out == 0), 0 otherwise ng: 1 if (out < 0),  0 otherwise. You know, the if = 0 is easy, I can have a NAND gate with it's input bussed to the output. But smaller than 0!?!?! How is that possible? I know the negative nums but nobody told me how many negative nums out of the 65356 (2^16) available ones you wanna use. Help me please
Reply | Threaded
Open this post in threaded view
|

Re: I don't understand the ALU flags

cadet1620
Administrator
HowDoICraftAgain? wrote
I built the ALU and everything but I need 2 things, the 2 flags. zr: 1 if (out == 0), 0 otherwise ng: 1 if (out < 0),  0 otherwise. You know, the if = 0 is easy, I can have a NAND gate with it's input bussed to the output. But smaller than 0!?!?! How is that possible? I know the negative nums but nobody told me how many negative nums out of the 65356 (2^16) available ones you wanna use. Help me please
I don't understand what you are saying about 'zr' and a Nand gate. Note that HDL is like soldering wires; you can connect more than one wire/bus to part outputs:
    Something(..., out=out, out[3..5]=threeBits, out=...)

For 'ng', review 2's-complement numbers. Which bit in 2's-compliment numbers indicates that the number is negative?

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

Re: I don't understand the ALU flags

HowDoICraftAgain?
Ohh yes the carry out, thanks brah :D I remember
Reply | Threaded
Open this post in threaded view
|

Re: I don't understand the ALU flags

HowDoICraftAgain?
But how do I select which bits I wanna flip and which I don't? Also how do I XOR a 16 bit input to a 1 bit one together? Thanks :)
Reply | Threaded
Open this post in threaded view
|

Re: I don't understand the ALU flags

cadet1620
Administrator
HowDoICraftAgain? wrote
Ohh yes the carry out, thanks brah :D I remember
Carry out from the Add16 is not available. One of the bits in 'out' is what you want for 'ng'.
But how do I select which bits I wanna flip and which I don't? Also how do I XOR a 16 bit input to a 1 bit one together?
What bit flipping are you talking about?

Xor 16 x 1 is a lot of typing. Assuming that you have an Xor16:
CHIP Xor16x1 {
    IN  a[16], b;
    OUT out;
PARTS:
    Xor16(a=a, b[0]=b, ... b[15]=b);
}
But think about this: Xor16x1 is just a conditional Not16 so it is the same circuit that you already have for 'nx'.

--Mark