ALU, struggeling with zr and ng implementation

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

ALU, struggeling with zr and ng implementation

ronaldmaas
Hi, I recently found the nand2tetris site and have started following the course. I'm really enjoying it and have upto now not had too much trouble implementing things. But now I've got stuck on the ALU in project 2. The first bit of the processing is fine, and I have written the ALU.hdl for that. It's passing all the test from the ALU-nostat.tst script. I am however struggeling to derive the values for the zr and ng flags that need to be returned. I'm pretty sure it shouldn't be very complicated, but I'm probably overthinking it. Anyone got any pointers of what to do and/or look for? Thanks, Ronald
Reply | Threaded
Open this post in threaded view
|

Re: ALU, struggeling with zr and ng implementation

ybakos
The ng bit should be on when the output of the ALU is a negative number. Think of the 16-bit ALU output: is there one wire that tells you if the number is negative or not? Hmmm....

The zr bit should be on when the output of the ALU is 0. Try to describe this to yourself logically in terms of the 16 bits of the ALU's output, like, "The output is zero if .... and ... ." Just realize that it may be easier to determine if the output is non-zero first, and then not the answer before wiring it to zr.
Reply | Threaded
Open this post in threaded view
|

Re: ALU, struggeling with zr and ng implementation

ronaldmaas
Thanks.

Also found the page Share some tips on ALU implementation.
Have got it all working now.


Ronald