I have an Arithmetic Logic Unit, as shown below (I also included a CircuitJS simulation of it, so it will be much easier to understand the inner working of said ALU).
‘x’ and ‘y’ are the 4-bit input nibbles (operands). (The ALU accepts Natural Binary Code as well as U2 negative numbers [Unfortunately I don’t know why, but “it just works…” – my lecturer has not explained it thoroughly, probably because of the lack of time] ); ‘zx’ basically zeroes the entire ‘x’ nibble regardless of what is currently written to it; ‘nx’ negates the ‘x’ nibble (it, however, may be possible to firstly zero the ‘x’ nibble and then negate it to achieve a nibble consisting of ones – 1111).
The same logic applies to ‘zy’ and ‘ny’. The ‘f’ input controls the operation done by the ALU. If ‘f’ is equal to 0, the ALU performs a logical AND operation. If, however, it is equal to 1, then the ALU performs an arithmetical sum operation (there is a full adder inside the ALU). The ‘no’ input simply negates the output of the ALU.
Below I attached an example table consisting of input values and expected results. Now my question is: How can I work out the combination of the inputs ‘zx’, ‘nx’, ‘zy’, ‘ny’, ‘f’ and ‘no’ that will give me these results: -x, x-y, y-x, x+1, y+1? The answers are shown below, in the after-mentioned table.
I understand the logic behind the other combinations, they are pretty trivial to work out (besides the ‘x OR y’, that requires the De’Morgan’s theorem), but I have no idea, how one could work out the required combinations for the mentioned results. I checked the combinations shown in the attached table, and they all seem to work, but I cannot imagine that someone plugged random combinations, observed the output and, using his/her mind worked out what they must have done… It’s pretty hard to wrap my head around this stuff. Thanks for every, even little bit of help :).
The table with inputs and expected outputs:
Here is the link to a paste that includes the code, which can be used in CircuitJS simulator: ALU simulation code
You can test the ALU by yourself by going to this website: CircuitJS, pressing File → Import From Text... and pasting the copied code.