In this post, I will talk about the ALU and the flags register of my 8-bit computer.
The arithmetical logical unit(ALU) is where all the computation happens in a computer. The ALU of this computer is very simple and only has the option to add or subtract numbers. So something like multiplication would have to be implemented in software.
The flags register stores the Carry(a carry occurs) and Is Zero(the result is a zero) flags that it receieves from the ALU.
When bits from the A and B register arrive into the adder they are automatically added and the result is sent out of the Sum output. If the bits from both registers are 1 the C_Out output will be also set to 1. This output is thne feed into the C_In input of the next adder.
To implement the subtraction one of the values(B register) is XOR-ed and the carry in(C_In) of the first adder is set to 1. If you want to know how and why exactly this will perform subtraction(despite the fact that the bits are getting added) search more about “twos complement” or watch Ben Eaters video about it here.
Finally, there is a tristate buffer to control whether the value is put on the BUS or not.
- If A and B are 0 the Sum and Carry shouldboth be 0.
- If A or B is 1 the Sum is 1 and Carry is 0.
- If both A and B are 1 the Sum is 0 and Carry is 1.
XOR Gate Truth Table
AND Gate Truth Table