|
This post was updated on .
So, you're right that ng and zr will never be 1 at the same time. You might understand why, but in case not (you were vague): it's simply because a number cannot simultaneously be equal to 0 and less than 0 (which are handled by outputting 1 for either zr or ng, respectively).
Here's how I wrote my jump code:
Assuming that only one of our jump bits is set in a given instruction...
If zr is 1 and the middle j value is equal to 1, we should jump (our value is equal to 0, and the "equal to 0" jump bit is set)
If ng is 1 and the first j value (reading from the left) is equal to 1, we should jump (our value is less than 0, and our "less than 0" jump bit is set).
The slightly more difficult portion is when our ALU output is greater than 0. With that, we can check if either zr or ng are equal to 1. If one of them are, our ALU output is NOT greater than 0. If both of them are 0, then the only other possibility is that the ALU output IS greater than 0. Based on this, we can generate and output a bit representing whether the ALU output is greater than 0, and check if it and the relevant jump bit are 1.
We don't need to write any additional code for the >= or <= comparisons; the conditions are satisfied by the above checks, which would output whether a value is greater than, equal to, or less than 0. Likewise, if none of the jump bits are set, we won't jump at all.
When do we want to load a bit for our PC? If we outputted a 1 for either of the three above conditions (checking a jump bit and the relevant bit to see if our ALU output meets that particular criteria), then we want to jump to the instruction outputted from the a register. Otherwise, our load bit is 0, and we either increment or reset the program counter, based on the inputted reset bit.
|