# Zr and Ng - ALU

4 messages
Open this post in threaded view
|

## Zr and Ng - ALU

 I'm a bit confused on the Zr/Ng part of the ALU. I was able to construct the part with all 6 Mux16's, based on what I was told in class and what I read on other posts. I think I have the zx, nx,...,no inputs figured out. If someone would like to see that, I can email it or something. Based on what I saw from another post, it seems like you take the output f(x,y). If it is zero, zr = 1, otherwise it is 0. And if output f(x,y) < 0, then ng = 1, otherwise it's 0. The only thing the book says about zr and ng is this: if out=0 then zr = 1 else zr = 0 // 16-bit eq. comparison if out<0 then ng = 1 else ng = 0 // 16-bit neg. comparison I'm not exactly sure where to go from here. The last thing I have done is negating the output. After that, I feel lost. // Negate the output     Not16(in=xyOut, out=xyNot);     Mux16(a=xyOut, b=xyNot, sel=no, out=out); // Zr/Ng
Open this post in threaded view
|

## Re: Zr and Ng - ALU

 Administrator DrZoo wrote I'm a bit confused on the Zr/Ng part of the ALU. ... I'm not exactly sure where to go from here. The last thing I have done is negating the output. After that, I feel lost. // Negate the output     Not16(in=xyOut, out=xyNot);     Mux16(a=xyOut, b=xyNot, sel=no, out=out); // Zr/Ng First, make sure that your ALU is passing ALU-nostat.tst. If it does, then the computation portion of your ALU is good. For the 'ng' output, think about 2's-complement numbers. What bit indicates that a number is negative? You can connect that bit to 'ng' in the final Mux16 in your ALU by adding a sub-bus connection to the Mux16's 'out'. For the 'zr' output, you need to detect when 'out' == 0. In this case all 16 of 'out's bits are 0. If any of the bits are 1, then 'out' != 0. You made a part that can detect if any one of its 8 inputs is 1. You will want to use two of them and a couple other parts to generate 'zr'. This will require two more sub-bus connections to the Mux16's 'out'. --Mark