Skip to content

ALU Operations

SELNameDescriptionlink
0000NOTNOT A#not
0001ORA OR B#or
0010XORA XOR B#xor
0011ANDA AND B#and
0100ADDA ADD B, CIN#add
0101SUBA SUB B, CIN#sub
0110INCA ADD 1, CIN#inc
0111DECA SUB 1, CIN#dec
1000SHLA SHL BY B#shl
1001SHRA SHR BY B#shr
1010ROTLA ROTL BY B#rotl
1011ROTRA ROTR BY B#rotr
1100MULA MUL B#mul
1101CMPA SUB B#cmp
1110NOOPA#noop
1111NOOPA#noop

The examples are simplified to 4 bit inputs & outputs

NOT

This does the bitwise NOT (~A) operation on A and returns the result in X/OUT. B and CIN is ignored.

OR

This does the bitwise OR (A | B) operation on A and B and returns the result in X/OUT. CIN is ignored.

XOR

This does the bitwise XOR (A ^ B) operation on A and B and returns the result in X/OUT. CIN is ignored.

AND

This does the bitwise AND (A & B) operation on A and B and returns the result in X/OUT. CIN is ignored.

ADD

This operation adds A and B using the RCA, in the future the RCA will be replaced with CLA. CIN is taken as an input for the adder circuit, so it can be used to increase the result by 1. Its purpose is to allow chaining ADD operations and allow carrying 1 between double words.

SUB

To save on transistors, SUB is just an ADD operation with B inverted (NOT B) and carry turned on. Because of that the COUT for this operation doesn't make sense, so multiple SUB operations cannot be changed to subtract bigger numbers than double word. For parity with the ADD operation, if CIN is 1, the carry for the add circuit is turned off, so it effectively means subtract 1.

INC

This is an operation, that adds constant 1 to A. B is ignored, but CIN isn't, so you can add 2 instead of one by enabling CIN.

DEC

This is the same as INC, but for subtracting. B is once again ignored and by enabling CIN, you can subtract 2.

SHL

This ALU uses a barrel shifter, so shifting by multiple bits doesn't have to be done in multiple operations. The output is A shifted by the 4 LSBs of B. (as shifting by more would have the same result) The last bit that was removed because of the shift is returned as COUT.

SHR

The same as SHL, but it shifts right.

ROTL

The same as SHL, but instead of throwing out the bits, they are added as LSBs.

ROTR

The same as ROTR, but it shifts left.

MUL

This ALU has only 8bit multiplier, so only lower 8 bits of A and B are used for this operation. Thanks to that, no HOUT is necessary, as the highest output is 16bits. CIN is ignored.

CMP

This is an operation, that could be replaced in the future, as it does the same thing as SUB, without CIN. The idea of this operation is to compare A and B and be sure CIN is 0, so we can write the comparison flags.

NOOP

There are no other operations I wanted to implement, so the last two SEL values act as no-operation, returning A and ignoring everything else. This might be changed in the future, as it can be implemented in the CPU and I might want to add some more operations sometime.