Some of you might remember when rokit boy made a 1-bit full adder in vanilla Mari0.
With the release of Mari0-SE beta and the fact that it included logic gates I decided to take circuits in Mari0 to another level.
I have created a 4 bit ALU that adds, compares and performs other arithmetical operations on binary numbers.
For those who don't know what an ALU is its basically what your computer uses to calculate numbers.
The ALU can perform several mathematical operations on 4-bit binary numbers.
If you do not understand how binary works or what 4-bit binary is, this should help:
The ALU has 2 4 bit inputs, 1 4 bit output, 1 3-bit OPCode input and 4 ALU flags.
More about flags:
The 'Flags' basically tell you different information about the numbers.
C : Carry out, this turns on if the output number is too big and had to 'Overflow'
Z : Zero, this turns on if the output number is zero (This might not sound too useful but in a real processor it is needed for the 'Jump If' instruction)
= : Equal, Inputs A and B are mathematically equal
A : A is larger than B, This turns on if input A is larger than input B.
Wires:
For decoration purposes I added power lines for the adder and the miscellaneous logic functions to show how it works and so that you can see the ALU calculate numbers as you go. I decided not to add power lines to the comparator and the OPCode decoder because I was running out of space and patience.
I was forced to make a tunnel/junction system for the decorative wires so that I don't go insane or run out of space:
Screenshots:
Hint: Off = 0 On = 1
You have 2 inputs at your disposal:
A
and B
The inputs are 4 bit binary as mentioned before.
If the first and second buttons are pressed you have entered the number '3'
You also have the OPCode:
There should be a list of different OPCodes later on in the post
Here is the output:
The output is also 4 bit binary,
(light off = 0 light on = 1)
And lastly here are the flags:
The flags are described above.
OPCodes:
000 = ADD
100 = NOT
010 = AND
110 = SHL
001 = SHR
101 = XOR
111 = OR
ADD = Add input A and input B together.
E.g. If input A = 1010 (5) and input B = 1001 (9) then the output is 0111 (14)
NOT = Inverts input A.
E.g. If input A is 0101 the output is 1010
AND = Only displays bits that are on both inputs.
E.g. If input A is 1101 and input B is 1010 the output is 1000
SHR = Shifts input A binary to the right.
E.g. If input A is 1100 then the output is 0110
SHL = Shifts input A to the left.
E.g. If input A is 0110 then the output is 1100
XOR = Only displays bits that are on only one input.
E.g. If input A is 1011 and input B is 1110 then the output is 0101
OR = Displays the bit if either input has it turned on.
E.g. If input A = 1100 and Input B = 0110 then the output is 1110