ALU

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

ALU

dmoeller
I don't understand how to make comparisons. For example. IF zx, then zero x. How do i do the IF comparison and once I do, How do i execute the THEN part? Also, comparing the output to zero seems easy, but how to i check if it is less than zero?
Reply | Threaded
Open this post in threaded view
|

Re: ALU

cadet1620
Administrator
You may not realize it, but you already wrote a part that does if-then-else.

In hardware the if-then-else structure is done by computing both options and then choosing between the options using a multiplxor.

Also, you can't change the input value, so you must generate a new wire.  The ALU looks more like a series of conditional assignments:
x1 = zx ? 0: x;
x2 = nx ? ~x1 : x1;
...

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

Re: ALU

dmoeller
im afraid I still don't understand. I know you can compare a value to 1 or 0 using And but i don't know how that helps.
Reply | Threaded
Open this post in threaded view
|

Re: ALU

cadet1620
Administrator
Also, comparing the output to zero seems easy, but how to i check if it is less than zero?
Sorry I missed the second half of the question.  I'm at work and somebody interrupted me in the middle of typing...

Don't think of testing for less than 0; rather test for negative. What bit of a binary number indicates that it is a negative number?

If you haven't found it yet, one thing that can simplify you status output code is that just like you can solder more than one wire to a physical part's output, you can have more than one "out=" on an HDL part.

Check out the example in appendix A, section A.5.3

--Mark



Reply | Threaded
Open this post in threaded view
|

Re: ALU

dmoeller
the MSB is the signed bit to mark if a number is negative. i would guess doing an
and (a=out[15], b=1, out=ZeroOut);
Reply | Threaded
Open this post in threaded view
|

Re: ALU

cadet1620
Administrator
dmoeller wrote
the MSB is the signed bit to mark if a number is negative. i would guess doing an
and (a=out[15], b=1, out=ZeroOut);
cadet1620 wrote
If you haven't found it yet, one thing that can simplify you status output code is that just like you can solder more than one wire to a physical part's output
Somepart (... out=out, out[15]=ng, ...);
And and two more out[]= to that part to make it easier to generate the 'zr' output.

--Mark