A full-fledged Minecraft processor: how does it work, how to program on it and what is it for?
Everyone probably knows that you can do absolutely everything in the Minecraft sandbox. Various digital circuits and processors have been created in Minecaft for a long time. But the processor I’m writing about is really unique! Its name is DjCPU8.
Why is it unique?For many reasons.Let's go in order: ')
1) Speed of work. This is still the fastest processor of this level in Minecraft. One instruction is executed in approximately 1 second. 2) The amount of memory. RAM already 256 bytes. I do not know other computers with such a memory capacity. 3) Computational abilities. 42 instructions. Works with arithmetic, logic, stack, I / O, registers, etc. 4) Assembler. In other processors, you need to enter the program in binary form. But in DjCPU8 you can enter its text. 5) Simplicity. It is impossible to work with such a simple computer with any other computer. 6) The breadth of use. I / O ports can be created anywhere.
DjCPU8 processor features: 1) Digitality - 8 bits; 2) Von Neumann architecture; 3) RAM 256 bytes; 4) Without clock generator. The average operation time is 1 second; 5) Data stack - 9 bytes; 6) 2 general purpose registers (RON); 7) 42 instructions; 8) System errors; 9) 1 user input; 10) 16 output ports; 11) Assembler.
Processor anatomy The picture shows the functional blocks in the processor in different colors:
- RAM - Control device (CU) - RAM read / write device - the device of giving a signal for reading the instruction, its decoding and zeroing of the necessary registers. - output to output ports - physically implemented assembler - stack - error detection system - various computational conversion units.
And there are a few small blocks.
How does he work
In order not to bore you, this subtitle will be very short.
Since the DjCPU8 architecture is fonnemanovskaya, it is clear that the instructions and data are in the same memory. At the moment the processor starts, a full reset of all registers and the stack occurs immediately. Then the device of signals (highlighted in blue) sends a signal to read data from the RAM. The resulting number is interpreted as an instruction. This number is fed to the CU (yellow color), where the instruction is executed.
Let's take load instruction as an example. This instruction reads the number from memory and places it in register A. So, first we read the number 3 from the memory. The number 3 is fed into the control unit. The VU decodes this number and understands that it is a load instruction. Then the control unit starts to perform the specified sequence of actions. First, the value of the register of the program counter is increased by 1. Then the second number is read, which is interpreted as an address. Suppose the address is 4. Then the CU sends a signal for reading a third time. A number is taken from cell 4. This number is placed in register A. A signal is given to read the next instruction. Everything, the instruction is executed. Just imagine, in one second the processor managed to turn to memory 3 times!
There are complicated instructions and simple ones. The simpler the instruction, the faster it is executed. But the average speed is about 1 Hz.
How to program on it?
Here is a small sign describing all instructions:
0 stop - Stop CPU 1 load RAM - Reads a number from RAM and places it in A 2 loadC const — Places a specific number of const in A 3 store RAM - Saves A to RAM 4 rand - Generates a random number in A (0..255) 5 add RAM - To value A adds value from RAM 6 sub RAM - A value is subtracted from value A from RAM 7 mult RAM - multiplies A by value from RAM 8 div RAM - Divide A by value from RAM 9 and RAM - Bitwise “and” operation: A and value from RAM 10 or RAM - Bitwise “OR” operation: A and value from RAM 11 not - Bitwise operation “NO” A 12 2x - Divides A by 2 13 x / 2 - Multiplies A by 2 14 compare RAM - F = A - RAM 15 jump to A - Unconditional jump to a cell whose address is in A 16 del RAM - Clears a cell in RAM 17 say - Displays the value of A in the chat 18 A-R1 - Forwarding from A to R1 19 A-R2 - Forwarding from A to R2 20 R1-A - Transfer from R1 to A 21 R2-A - Transfer from R2 to A 22 inc - Increase A by 1 23 dec - Decreases A by 1 24 push - Move a number from A to the stack 25 pop - Move number from stack to A 26 pushC const - Shove the const onto the stack (A becomes equal to const) 27 in - CPU pauses, reads the number from the read port in A 28 out - Forwarding a number from A to Port 29 setPort const - Set the Port Port value to const 30 print - Sends a number to port 0 31 jump const - Unconditional jump to const cell 32 jump if A const - If A> 0, move to cell const, otherwise to the next cell. 33 jump if F const - If F ≠ 0, the transition to the cell is const, otherwise - to the next cell 34 jump If not F const - If F = 0, go to the cell const, otherwise - to the next cell 35 storeR1 - Stores A value in memory at the address that in R1 36 storeR2 - Stores the value of A in memory at the address, which in R2 37 loadR1 - Loads the value at address R1 to A 38 loadR2 - Loads the value at address R2 in A 39 incR1 - Increases R1 value 40 decR1 - Reduces the value of R1 41 incR2 - Increases R2 value 42 decR2 - Reduces R2 value
Sample program:
loadC 123 say
About the instructions. There are two types of them - with and without a parameter. The parameter must be in the next cell after the instruction. For example, loadC is an instruction with a parameter. The next number 123 is just a parameter for loadC. What does loadC do? This instruction takes a number and places it in register A. So, the processor has loaded the number 123. What next? And then he can do anything with this number! For example, display a number in the chat. The say command does just that.
And now about the parameters. They also have two types - const and RAM. The const parameter is just a specific number. The loadC command just requires a specific number. And the RAM parameter is more interesting. This is not just a number, it is the address of the place where you need to get a number. So:
load 123 say
Unlike the previous one, this program will work quite differently! The load statement has a different type of parameter - RAM. Therefore, the number 123 is already an address. What will happen? The processor, instead of being satisfied with the number 123, now climbs into memory and, at address 123, gets a number. But since we did not record anything there, he would get a zero. After executing this program, register A will become zero. Clear?
You will learn more from my guide . And here is an even more convenient sign .
What did I create this processor for? Noticed that many ask this question. And even supplement - "I could make money better."
The answer is simple - it brings me pleasure. Someone is having fun with PvPshit in DotA, someone is drawing, someone is programming, and I am doing a processor.
And plus to this, during the creation of my processor, I realized how a real processor actually works.