# How to ng and zr?

7 messages
Open this post in threaded view
|

## How to ng and zr?

 This post was updated on . So, I implemented my ALU, and suprisingly, it was rather easy and took me a short time to do it.  I don't think this is an elegant solution but it passes the nostat test. However, I am having a hard time with ng and zr. Here's what I have been able to figure out so far: If I check the first bit of the output, and if it is 1, then ng is 1. Something like if out[0] = true, then ng=true. This is rather hard to implement since it's not possible to connect output to anywhere. And for zr, if the whole output is zero, then zr is 1. If out[0..15]=false, then zr=1. I think this one is doable with an AND gate but then again, it's impossible to connect the output to anywhere. Any suggestions as to how I can tackle this problem? I feel like I am close to the answer. Any help is appreciated.
Open this post in threaded view
|

## Re: How to ng and zr?

 Administrator Please don't post solutions -- let others learn by struggling with it the same you you did.
Open this post in threaded view
|

## Re: How to ng and zr?

 Administrator In reply to this post by kingofbuffs kingofbuffs wrote However, I am having a hard time with ng and zr. Here's what I have been able to figure out so far: If I check the first bit of the output, and if it is 1, then ng is 1. Something like if out[0] = true, then ng=true. This is rather hard to implement since it's not possible to connect output to anywhere. And for zr, if the whole output is zero, then zr is 1. If out[0..15]=false, then zr=1. I think this one is doable with an AND gate but then again, it's impossible to connect the output to anywhere. Any suggestions as to how I can tackle this problem? I feel like I am close to the answer. Any help is appreciated. Not quite sure what you mean by it not being possible to connect output to anywhere. Output of what? The part as a whole? Remember that you can use the output of a part many times. So you can do things like And(a=fred, b=sue, out=tim, out=tom); Also, give some more thought to how you are going to use that And gate to get zr. You're not far off, but not quite there.
Open this post in threaded view
|

## Re: How to ng and zr?

 This post was updated on . Apologies, I thought it would be fine if I put it in a link. I didn't realize you could have different outputs with different names. It's a little odd, since And gate is supposed to have only one output, so it didn't really dawn on me. For ng I am using the 2's complement rule, written in the book: "The codes of all negative numbers begin with a 1". So, if I could just check if the first bit is a 1, that would solve it. Going with your example, And(a=fred, b=sue, out=tim, out=tom); And(a=tom[0], b=true, out=ng); This seems like it should work but it throws an "sub bus of an internal node may not be used" error. I don't really understand this, since I feel like it should be possible to use a sub bus of a given output. (I wrote a paragraph explaining my thought process as to how I was planning on finding zr, only to realize I read your reply wrong. In the end, I found  the solution.)
Open this post in threaded view
|