Time to put it all together

Now we've built the constituent parts, it's now time to put everything together into our ALU chip.

The ALU has two outputs: the 8-bit result of the operation that was performed, and a 4-bit "flags" value which contains information about the calculation.

flags

You should set the flags according to the following logic:

FlagLogic
Overflow1 if the addition of two numbers with the same sign bit produces a result with a different sign, or if the subtraction of two numbers with different signs produces a result with the same sign as the number being subtracted.
0 otherwise.
Carry / Borrow1 if an addition or subtraction operation results in a carry / borrow.
0 otherwise.
Negative flag1 if the sign bit (most significant bit) of the result is 1.
0 otherwise.
Zero flag1 if every bit of the result is 0.
0 otherwise.

The ALU has three inputs: the first and second 8-bit operands, and a 4-bit "opcode" which selects the operation to be performed.
This processor's ALU will use the following opcodes:

OpcodeOperationExplaiation
0000add Adds the second operand to the first, setting the carry in to 0.
0001subtract (sub)Subtracts the second operand from the first, setting the carry in to 0.
0010add with carry
(adc)
Adds the second operand to the first, setting the carry in to the value of the carry flag.
0011subtract with borrow
(subb)
Subtracts the second operand from the first, setting the carry in to the value of the carry flag.
0100nandEach bit of the output is the result of NANDing together the respective bits of each operand.
0101xorEach bit of the output is the result of XORing together the respective bits of each operand.
0110shift left
(sll)
Each bit of operand 1 is shifted to the left by the number of places specified by operand 2.
0111shift right
(srl)
Each bit of operand 1 is shifted to the right by the number of places specified by operand 2.
1XXXmove
(mov)
Operand 2 is passed straight through to the result. No operation is performed.

This is the most complicated part of the process, and it's OK if you don't quite understand everything yet. You can use the green links to get more information about certain words, and now might be a good time to ask your tutor for help if you are truly stuck.

Start building

Once you are finished, you can return to the CPU.