A full-fledged processor in Minecraft: how it works, how to program on it, and what is it for?

Everyone probably knows that absolutely everything can be done 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 take it in order:

1) Speed. This is so far the fastest processor of this level in Minecraft. One instruction takes about 1 second.
2) The amount of memory. RAM is already 256 bytes. I do not know other computers with such a memory capacity.
3) Computational abilities. 42 instructions. Works with arithmetic, logic, stack, input / output, registers, etc.
4) Assembler. In other processors, you need to enter the program in binary form. But in DjCPU8, you can enter it in text.
5) Simplicity. It is impossible to work with any other computer so simply and pleasantly.
6) The breadth of application. I / O ports can be created anywhere.



Characteristics of the DjCPU8 processor:
1) Bit depth - 8 bits;
2) Von Neumann architecture;
3) RAM 256 bytes;
4) Without a clock. The average operation time is 1 second;
5) Data stack - 9 bytes;
6) 2 general purpose registers (RON);
7) 42 instructions;
8) Error system;
9) 1 user input;
10) 16 output ports;
11) Assembler.

Anatomy of the processor
The picture in different colors shows the functional blocks in the processor:



- RAM
- Control device (UE)
- RAM reading / writing
device - a signal supply device for reading an instruction, its decoding and zeroing of necessary registers.
- output to output ports
- physically implemented assembler
- stack
- error detection system
- various computing and transforming units.

And there are a few small blocks.

How it works

In order not to bore you, this subtitle will be very short.

Since the architecture of DjCPU8 is Fonneimann, it is clear that the instructions and data are in the same memory. At the time of starting the processor, all registers and the stack are completely reset immediately. Then the signal supply device (highlighted in blue) sends a signal to read data from RAM. The resulting number is interpreted as an instruction. This number is fed to the control unit (yellow color), where the instruction is executed.

Let's take the load statement as an example. This instruction reads a number from memory and places it in register A. So, first we read the number 3 from memory. The number 3 is supplied to the control unit. UU decodes this number and understands that this is a load instruction. Then the UE begins to perform a given 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 UE sends a read signal a third time. The 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 complete. Just imagine, in one second the processor managed to access the memory 3 times!

There are complicated instructions, and there are simple ones. The simpler the instruction, the faster it is executed. But the average speed is approximately 1 Hz.

How to program on it?

Here is a small label describing all the instructions:
0 stop - CPU stop
1 load RAM - Reads a number from RAM and puts it in A
2 loadC const - Puts a specific const number in A
3 store RAM - Saves A in RAM
4 rand - Generates a random number in A (0..255)
5 add RAM - Adds the value from RAM to the value A
6 sub RAM - From the value A takes the value from RAM
7 mult RAM - Multiplies A by the value from RAM
8 div RAM - Divides A by the value from RAM
9 and RAM - The bitwise operation “AND ”: A and value from RAM
10or RAM - Bitwise operation “OR”: 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 transition to a cell whose address is in A
16 del RAM - Clears a cell in RAM
17 say - Displays the value A
18 A-R1 - Transfer from A to R1
19 A-R2 - Transfer from A to R2
20 R1 -A - Forwarding from R1 to A
21 R2-A- Transfer from R2 to A
22 inc - Increase A by 1
23 dec - Decrease A by 1
24 push - Move a number from A to the stack
25 pop - Move the number from the stack to A
26 pushC const - Push const into the stack (A becomes equal const)
27 in - pause the CPU, reads the number from the read port in A
28 out - Sends the number from A to Port
29 setPort const - Sets the value of the Port to const
30 print - Sends the number to Port 0
31 jumpconst - Unconditional transition to the cell const
32 jump if A const - If A> 0 go to the cell const, otherwise to the next cell
33 jump if F const - If F ≠ 0, go to the cell const, otherwise to the next cell
34 jump If not F const - If F = 0, go to the const cell, otherwise - to the next cell
35 storeR1 - Saves the value A in memory at the address in R1
36 storeR2 - Saves the value A in memory at the address in R2
37 loadR1 - Loads a value at address R1 in A
38 loadR2 - Loads a value at address R2 in A
39 incR1- Increases the value of R1
40 decR1 - Decreases the value of R1
41 incR2 - Increases the value of R2
42 decR2 - Decreases the value of R2


Program Example:
loadC
123
say


About the instructions. There are two types of them - with and without a parameter. The parameter should be in the next cell after the instruction. For example, loadC is an instruction with a parameter. The next number 123 is just the parameter for loadC. What does loadC do? This instruction takes a number and puts it in register A. So, the processor loaded the number 123. What next? And then he can do anything with this number! For example, display a number in 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 already more interesting. This is not just a number, it is the address of the place where you need to get the number. So:
load
123
say
Unlike the previous one, this program will work in a completely different way! The load instruction has another 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, is now crawling into memory and at 123 takes out the number. But since we didn’t write anything there, he will get zero. After executing this program, register A will become equal to zero. Clear?

You will learn more from my guide .
And here is an even more convenient tablet .

Why did I create this processor?
I noticed that many are asking this question. And they even complement it - “it would be better to make money”.

The answer is simple - it brings me pleasure. Someone is amused by the fact that PvPshit is in Dota, someone draws, someone programs, and I make a processor.

And plus to this, during the creation of my processor, I realized how the real processor actually works.

And finally, here's a video review:



Thanks!

Also popular now: