4-bit calclulator using logic gates Mari0 SE

Mapping related threads and questions go in here!
Post Reply
User avatar
penguin321
Posts: 165
Joined: 03 Mar 2012, 23:01

Post » 16 Mar 2014, 02:33

Hello.

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:
https://www.youtube.com/watch?v=VBDoT8o4q00
4 bit means 4 0's in a binary number.
Image
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:
Image
Screenshots:
Hint: Off = 0 On = 1
You have 2 inputs at your disposal:
A
Image
and B
Image
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:
Image
There should be a list of different OPCodes later on in the post

Here is the output:
Image
The output is also 4 bit binary,
(light off = 0 light on = 1)

And lastly here are the flags:
Image
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
Download:
https://dl.dropboxusercontent.com/u/85596363/ALU.zip

Please post feedback and if you find any bugs please tell me!

Credits:
Everything: Penguin321
Mari0: Maurice
Inspiration: Rokit boy
Last edited by penguin321 on 16 Mar 2014, 17:29, edited 1 time in total.

User avatar
Superjustinbros
Posts: 2119
Joined: 29 Mar 2012, 20:39
Contact:

Post » 16 Mar 2014, 09:20

Oh boy, this'll be an intresting map to play.

User avatar
SauloFX
Posts: 556
Joined: 26 Feb 2014, 02:52

Post » 16 Mar 2014, 18:45

This is so mathematic that i'm confused,nice job!I DON'T UNDERSAND THIS MAP,MATH YOU WON AGAIN!

User avatar
rokit
Posts: 2095
Joined: 03 Feb 2012, 00:47

Post » 16 Mar 2014, 20:17

Nice. Add a display like on a calculator.

User avatar
penguin321
Posts: 165
Joined: 03 Mar 2012, 23:01

Post » 16 Mar 2014, 22:01

SauloFX wrote:This is so mathematic that i'm confused,nice job!I DON'T UNDERSAND THIS MAP,MATH YOU WON AGAIN!
This video explains binary and how binary addition works really well:

Post Reply