4-bit Processor
additional credits:
Alexthesax: Program stack.
View it in normal mode. There is too much electricity for fire mode.
Current status:
Almost complete, there are a few bugs that appear because powder toy has a habit of glitching. For example, about 10% of the time a program will fail because powder toy glitches and a switch is not turned on properly when it should do. This is not a problem on my behalf, but sadly I have to deal with it until I can get around it. Another resitriction I have come across is having to define a target register for an operation on the next line, rather than defining the target on the same line as the operation. This is because when doing it on the same line I have encountered timing problems. I also intend to add a function that allows you to clear a designated register. For now I haven't included that.
This is my first processor, I created it in about 10 hours, one day of work. It is fairly simple and only really has basic functionality because of powder toys size limitations.
!!! There is no overflow detection and all bits are unsigned (ie it will not calculate negative numbers or detect overflow) !!!
Here are the functions available:
While the processor is 4 bit, it uses 19 bit instructions. These instructions are incremented into fields for specific tasks.
There are 5 4-bit registers available.
The is a 5-bit 7 segment display available.
You can load a constant (ie a value of your choice) to any register.
Arithmetic functions available include:
Addition
Subtraction
AND
OR
XOR
Instruction Arcitecture
First three bits (from the left) define the function. Here are the functions.
000 = no function
001 = converts B to a 7 segment display
010 = addition (adds A and B)
011 = subtraction (subtracts B from A)
100 = XOR
101 = AND
110 = OR
The next four bits are used to define a constant to place in a register.
The register is defined by the INPUT REGISTER FIELD.
0000 = nothing
0001 = put 1 in the defined register
0010 = put 2 in the defined register
...
...
...
1111 = put 15 in the defined register
The next four bits are used to define the INPUT REGISTER FIELD. This field is where
a value will be stored after it was operated on. It is also used to store constants.
There are 5 available registers, therefore only 0001, 0010, 0011, 0100 and 0101 will work.
These values target the specific registers from left to right accordingly.
The next four bits are used to define A. A is the first variable used in an operation,
and A will come from one of the 5 registers as defined in this field. A can be either
0001, 0010, 0011, 0100 or 0101.
The next four bits are used to define B. B is the second variable used in an operation,
and B will come from one of the 5 registers as defined in this field. B can be either
0001, 0010, 0011, 0100 or 0101.
Here are some example instructions.
Place 5 in register 1:
000 0101 0001 0000 0000
Place 7 in register 2:
000 0111 0010 0000 0000
Add register 1 and register 2 and place the result in register 3:
010 0000 0000 0001 0010
010 0000 0011 0001 0010
(As you can see I have used two lines in the instruction. The first tells the
processor what operation (add) and what to operate on (reg 1 and reg2), then the
second line tells it to do the same thing except it also defines a register to
place the result, in this case 3. The only reason I have broken this instruction
up into two pieces is because I am experiencing difficulties with the
INPUT REGISTER FIELD, in that it does not function properly if the INPUT REGISTER
is defined on the same line as a function (such as add or subtract) or if an
INPUT REGISTER was already defined in the previous line. Because of this it also
means that you must leave an empty instruction between two instructions such
as this:
000 0001 0101 0000 0000 (put 1 in register 5)
and (leave an empty instruction here)
000 0011 0010 0000 0000 (put 3 in register 2)
also make sure to leave an emtpy instruction between to subsequent instrutions that involve a different function))
HERE ARE SOME OTHER INSTRUCTION EXAMPLES.
Subtract register 3 from register 2 and place the result in register 5:
011 0000 0000 0010 0011
011 0000 0101 0010 0011
Display/output register 5:
000 0000 0000 0000 0101
001 0000 0000 0000 0101
HERE IS AN EXAMPLE PROGRAM:
(The program will place a constant of 7 in register one, then place
a constant
of 3 in register 2, then add register 1 and register 2 and place
the result in
register 3. It will then subtract register 2 from register 1 and
place the result
in register 4. It will then perform the operation OR on register
3 and
register 4, placing the result in register 5. Finally it will take
register 5 and put
it into B, it will then output B to a 7 segment display.)
000 0111 0001 0000 0000 (store constant 7 to register 1)
000 0000 0000 0000 0000 (blank instruction)
000 0011 0010 0000 0000 (store constant 3 to register 2)
010 0000 0000 0001 0010 (ADD register 1 and register 2)
010 0000 0011 0001 0010 (Same as previous, except it defines register 3 as destination)
000 0000 0000 0000 0000 (blank instruction)
011 0000 0000 0001 0010 (SUBTRACT register 2 from register 1)
011 0000 0100 0001 0010 (Same as previous except it defines register 4 as destination)
110 0000 0000 0011 0100 (OR operation performed on register 3 and register 4)
110 0000 0101 0011 0100 (Same as previous except it defines register 5 as destination)
000 0000 0000 0000 0101 (Tells processor to output register 5 to B)
001 0000 0000 0000 0101 (Tells processor to output B to a 7 segment display)
Here is a save running the example program. It will be sucessfull about 90% of the time, however sometimes glitches
due to powdertoy not functioning properly can cause abnormal results.
Thanks guys. I will probably be redesigning this to look more simple and clean. There are about of instances where I used complex switches and I could have just used an AND gate lol.
Doing this will probably get rid of the switch glitch (if you tried the example program I provided and you got an answer other than 14, it would have been from the switch glitch). I will also the ability to clear registers via an operation, and put information in the same register than is being operated on (which cannot be done atm). I will look into using array for memory to make the registers smaller and allow for more registers. But yeah I usually make things that are at first pretty crude and spaced out, then I remake them in a much more compact/functional fashion.
Airstrike, I actually don't know what is going on with that at the moment. I haven't been on powder toy that much lately, but I just finished my exams so I will be more active and hopefully we can actually get into finishing that.