This page is currently being rewritten and updated as of April 2018, please do not delete yet, see talk page.
|This page is a work in progress and needs your help|
This article aims to examine the design and implementation of redstone computers in Minecraft.
See Chapter 1, Tutorial on Building a Computer, for a detailed tutorial on building a computer in Minecraft and how to expand and improve on the example. Does not require any extensive knowledge of Computer Science. NOT FINISHED.
See Chapter 2, Planning a Redstone Computer, for basic computer concepts of designing and understanding a redstone computer in Minecraft. Does not require any extensive knowledge of Computer Science.
Chapter 3 is hidden and currently to be deleted.
- 1 Overview
- 2 Chapter 1: Tutorial on Building a Computer
- 3 Chapter 2: Planning a Redstone Computer
- 3.1 Fundamentals of a Computer
- 3.2 Machine-Architecture
- 3.3 Computer Data Storage
- 3.4 Execution Model
- 3.5 Word sizes
- 3.6 Instruction Set
- 3.7 Architecture of the Computer
- 4 Tips
- 5 See also
- 6 References
Computers facilitate the implementation of ideas which are communicated from humans through programming.
This article will explain the basics of designing and building a computer in Minecraft, assuming the reader is fairly familiar with redstone and computers to a basic conceptualization.
All computer systems have at least one processing unit. During operation, processing units execute instructions stored in the computer's memory. For a good start on Minecraft computers you should learn computer science. There are many sources and tutorials to learn computer science but for a basic start I recommend the Crash Course on Computer Science especially episodes 1-8. Although it isn't completely thorough it can work as a basis in your understanding of computers.
Most computers in Minecraft are made of redstone, redstone torches, and repeaters, leading into sticky pistons or redstone lamps which are controlled using a series of buttons, levers, pressure plates, etc.. Other proposed ideas (not covered) are to use hoppers, mine carts or boats with redstone.
See chapter 1, Tutorial on Building a Computer, for a detailed tutorial on building a computer in Minecraft and how to expand and improve on the given example. Does not require any extensive knowledge of Computer Science as it will be explained.
See chapter 2, Planning a Redstone Computer, for basic computer concepts of designing and understanding a redstone computer in Minecraft. Does not require any extensive knowledge of Computer Science although will delve quite deep into it.
Computers can be used in many ways, from creating a smart house to using it to run a whole city. It could also be used in mini-games, as it can store info about who has the high score, and calculate if it is possible to beat this score. The uses of a computer are almost infinite. Please note that due to their extremely slow speed, as well as their large size, redstone computers are difficult to find practical applications for. Even the fastest redstone computers take seconds to complete one calculation and take up many blocks worth of space.
However, mods which change your tick rate such as TickrateChanger will significantly speed up the computer's speed, as well as Minecraft.
Chapter 1: Tutorial on Building a Computer
Redstone logic closely reflects binary logic, as redstone can be either on or off, and can, therefore, be interpreted as 1s or 0s. The reader must be familiar with at least a basic understanding of binary and the conversion of decimal to binary (base 10 to base 2). There is an excellent article which explains that. Please read the Architecture of building the Computer section as we will be following that plan, it is located in this article, thank you.
This chapter will focus on the application of the knowledge and manipulation of redstone to create a simple 4-bit computer. 4 bits means the computer will be able to count up to the number (24 - 1) = 15, having four channels on their bus. A computer of this scale is not very capable of large tasks, and can only execute very simple instructions and on the contrary, an 8-bit computers can count to the number (28 - 1) = 255 and are therefore more practical for basic programs such as the Fibonacci sequence or Fizz buzz. More about this in the third chapter of this article. So why a 4-bit computer? Choosing to build a 4 bit computer is a decision to allow for you to understand the basic concept of computer design and its integration with Minecraft, and how you can expand on these ideas and customize a computer suitable for your needs - it also avoids any confusion with more complex tasks the computer can do, it is best to start walking before running.
This is why you can only increment to 15 on a 4 bit computer.
...adding another one would only loop it back and it would return 0.
There are three primary design objectives for a computer in Minecraft, to make your computer most suitable for your task of design.
How small is the computer? Real life computers will also worry about power usage if they worry about compactness, as they are most likely designing a laptop. In Minecraft, designing a survival computer will most likely emphasize on this point
How much memory can it hold? How many bits and numbers can it count up to? The is important for large-scale computers, say ones which can recite the alphabet at least needs to remember the alphabet, and words.
How fast can it do operations? Is it optimized to run its tasks? Custom designing and building a computer will significantly increase its speed as more redundant wiring and code could be switched to purpose-built hardware and software. This is apparent in some real-world supercomputers which are programmed to run one task very, very efficiently. The speed of computers in Minecraft is very slow, therefore a mod, such as TickrateChanger could be installed for the client to significantly increase the speed of the game, and therefore the computer.
Building an Arithmetic Logic Unit
The Arithmetic Logic Unit referred to as the ALU will compare and perform mathematical operations to binary numbers and communicate the results with the Control Unit, the central component of the computer (and Central Processing Unit but that is going to be as big as the computer itself). Many tutorials will want the reader to build an ALU first, and therefore is covered very widely around the internet.
The ALU we will be building can perform four important operations on two inputs and return a correct output. A, B, being both 4-bit inputs
- A+B (Add A to B)
- A-B (Subtract B from A)
- A>B? (Is A more than B?)
- NOT A (The opposite of A)
Albeit used for more powerful computers, there are other commands that demand more of the ALU; e.g. incrementing or decrementing A or B by one, or perform no operation at all. There can also be multiple ALUs inside a computer, as some programs require many operations, which do not depend on the previous operations and delegating the commands to different ALUs could significantly speed up the process.
Another important part of the ALU are its arithmetic flags and comparison flags. There are essential ones but you can also add more to a non compact size computer. A basic ALU has a 
- Zero flag, or a flag that indicates if the output is zero.
- Overflow flag, represents if the number is to large or small to fully represent.
- Negative flag, indicates if the output is negative.
Adding two numbers
In an adding unit, for each bit (for our computer, we require four, hence 4-bit), there is a full adder. The full adder will take three inputs, each input can be either 1 or 0. The first two will be the user's input and the third will be the carry input. The carry input is the output of the previous full adder, this will be explained later. The adder will output two statements: first, the output and then the carry output, which is sent as input into the next full adder, a place value up. For example, I wish to add the number 0101 to 1011. The first full adder will consider the first place value, 1 and 1 as their two inputs (we are reading right to left). There is no carry input as there is no previous full adder. The full adder will add 1 and 1; which is 0, and carries a 1 to the next place value. The next full adder would add 0 and 1 and the carry input would be 1 which the previous full adder stated. The output of 0 and 1 would be 1 but there is a carry input of 1 and therefore will add 0 and 1 and 1, which is 0 and carries a 1 to the next place value. Reviewing addition in binary should resolve any confusion.
All ALUs, to perform adding operations require the presence of multiple adders. Each two bits will feed into an adder which when joined with other adders, will produce an output which is the sum of the two bytes added together. An adder has an input, an output and two carry input/output as would a person carry when doing the addition of 9 + 1 or 01 + 01. The adders are made of logic gates which is possible by the nomenclature of binary. Tutorials/Advanced_redstone_circuits gives a very detailed look into full adders and half adders, for now, there is a schematic of how to construct one. It gives four inputs/outputs and should be connected with other adders to create a unit. For this example, we will connect four adders together in our four bit computer so that we can take in all four bits to make an output. There will be an input carry missing from the first adder, this is because there is nothing to carry from the bit before it, it is the first bit. The input carry will remain at zero. There will also be an output carry missing from the fourth adder, and the output of this will be ignored as we can only support four bits. The additional fourth carry output is wired to the overflow flag to signify the operation couldn't be done. This is called binary overflow.
So basically, go into Minecraft and build a full binary adder (picture show) and connect them up. There should be eight inputs and outputs. Try placing levers and redstone lamps at the respective end to test your creation. So 0010 + 0011 should yield 0101 (2 + 3 = 5, we are reading right not left).
A computer takes care of numbers less than one by forms of float-point arithmetic, it is only so useful in larger-bit computers (16-64 bits) and computers which do need to use numbers less than one. Floating-point arithmetic or Arbitrary-precision arithmetic are two ways to achieve this. Another simpler but less efficient way would be to assign all numbers a power of two so that they are 'bumped up' by the power of two chosen. The player must do this to every number and assume the one as one times the power of the two you have chosen. For example, 5 = 1012 so 5 × 23 = 1010002; five is bumped up by three. So now, one in your new system would be 1 × 23 = 10002 and that would leave room for 0.1, 0.01 or 0.001; 0.01 * 23 = 102. This leads to a more complicated setup for your computer.
Subtracting two numbers
Subtraction of numbers in binary is just as simple as. There is a way we can cheat in using our adders. If we turn on the first carry bit we can turn our adder into a subtractor. You can learn more about this in the Tutorials/Advanced redstone circuits page. It is depicted in the photo on the right.
This poses the complexity of signed numbers. If the player subtract a number that results in a negative number it can cause numbers to be signed and require another bit to show if they are signed. This is represented by adding a negative flag to be outputted and possibly stored.
Chapter 2: Planning a Redstone Computer
A redstone computer can be planned very much like a real computer, following principles used in computer design and hardware architecture. There are several key design decisions that will affect the organization; size and performance of your prospective computer should be made concretely prior to the construction of specific components.
Building a redstone computer will require the understanding of these five concepts and consider the most suitable approach, which would be most practical for your computer.
- Machine-Architecture (Components of a computer, what are they and what they do)
- Execution Model (The organization of components, making them efficient)
- Word Size (How many bits the system uses. Usually, powers of 2, around 4, 8, 16 bit is normal in Minecraft)
- Instruction Set (The instructions to be performed by the CPU).
and we will be applying this knowledge and plan the architecture of our CPU in the last section. This CPU will then be built in the next chapter.
Fundamentals of a Computer
A computer is a machine which has the ability to
- Read and write from a memory which can be addressed
- Perform comparisons on the state of the memory, and perform an operation as a result of that. These operations include rewriting memory.
- Start functions based on content written in the memory. We call such content ‘programs + data’, and the act of writing them programming.
A very notable example of this is the most basic concept of computing, a Turing machine, where the machine will read from one infinite line of code and a instruction set in order to complete a function.
Designing and building a Turing machine in Minecraft is possible. This however, is not covered as we will be designing something more basic.
There are five fundamental components in a basic modern computer. These are essential in order to produce a functioning computer and manipulate data by performing computations.
Arithmetic Logic Unit (ALU) (optional, but is normally present)
- Perform adding and subtracting
- Compare booleans using logic gates
Control Unit (CU)
- Perform/Execute instructions sent to it
- Communicate with all components
- Store and return data from memory
- Return instructions, sent to the CU
- Can be set, but doesn't need to be as often as the Data Memory
Input/Output devices (I/O)
- Allows the computer to communicate with the world and the player.
- Can input information the computer (button push, daylight sensor)
- Can output information from the computer (redstone lamp, note block)
Computer Data Storage
There are many methods of storing data, in Minecraft or in real life. The states of memory usually are binary, either on or off and can be computed with boolean logic.
In a computer, there are three types of storage. Keeping in mind that increasing the device's capacity would increase its size, each type would have a speed and capacity appropriate to it.
These are the storage which directly accessible to the CPU, referred to as memory and is fastest to access but usually is smaller in capacity for it to be addressed quicker.
Registers & Flags
Fastest, are the memory stored within the CPU. These are registers and flags as they can be set almost instantaneously and do not require any address sent to it as there is only one byte stored in each register. Redstone bits which can be toggled are extremely large but can be toggled within 2 ticks. This requires a very large amount of space but is perfect for caches and registers. The redstone is also required for logic gates (not shown) to set the bit, as in the images, sending an input would cause the bit to flip. The gate would take up more space. Registers could also utilize locking redstone repeaters and timing them correctly. This is explained below, in RAM). With the use of a computer clock, it may not be necessary to build registers. Registers are useful for when the data goes through the line before either the CU or ALU is ready to process it. It would save it to the register and wait until the CU or ALU can perform its function.
Second to those are caches, which feed information into the processor. In real life, they are separated into levels, each one with separate speed and capacities.. It is useful for the same reason as the registers.
Random Access Memory (RAM)
Thirdly is Random Access Memory (RAM), this is much slower than the caches and registers as they have address systems. They are connected to three busses, data bus, control bus and the address bus. The data is sent through the data bus, either setting the RAM or getting values from the RAM. The control bus tells it whether it is being get or set. The address bus tells the RAM where the byte is. Refer to the Architecture of the Computer to understand this more in-depth. RAM is very useful and could fully replace tertiary memory (explained below) because of its non-volatility in Minecraft. Volatile means that when power is lost, it will lose information. The RAM will not lose information unlike in real life, and therefore in an excellent method of storing information.
The RAM in the first case is utilizing the locking redstone repeaters with correct timing. This requires a bit of a plan but is very space efficient. The conversion of a bus to the lines in order to lock the redstone repeaters also requires setting timings. This is time-consuming, much more than the registers, however, is very compact and efficient. The address bus (green) would turn in binary to unlock a certain byte, either to be read or set by the control bus (second line, on the left).
Most often, making it volatile has no use in Minecraft, so the easiest way to make some is to use d-flip-flops and to add a reading and writing function. The bottom image shows instead of locking repeaters, it uses d-flip-flops which is much more space inefficient but simpler to build. D-flip-flops work more or less like locked repeaters, one input - if on, unlocks in until the input is off and the other will set it once unlocked. The output can be read as a bit and with a NAND gate, be ignored or put onto the bus. This is gone over in detail in the second chapter, Tutorial on building a Computer. Excuse the texture pack.
Random Access Memory also known as RAM is a kind of memory used by programs and is volatile. Volatile means that when the power is lost, it will lose information. Most often, making it volatile has no use in Minecraft, so the easiest way to make some is to use d-flip-flops and to add a reading and writing function.
These are equivalent of HDDs and SSDs. There is a very compact storage technique, involving redstone comparators with the ability to store up to 1KB, being practically sized.
Third and last, is a Tertiary memory, which requires a lot of time to read/write but can hold massive amounts of information at the expense of speed. Real world tertiary storage use a mechanism of mounting the memory which takes about a minute for each drive. This is used for archival purposes and for memory which is rarely used. In Minecraft, a system where shulker boxes are used and block in the shulker boxes must be sorted out by a sorting system to represent a form of data. The read/write speed is fairly slow due to the massive amount of comparators and a lot of time is required. Aforementioned mods could speed up tickrate and eliminate this problem, however. This is used for storing long-term data which needed to be loaded at the beginning of a program or rarely due to its poor read/write speed and large capacity. This is the equivalent of a real computer's hard disk or solid-state drive.
The technique of storing blocks of instructions called programs within memory is what allows computers to perform such a variety of tasks.
The apparatus employed by a computer for storing and retrieving these programs is the computer's Execution Model.
Two of the world's most successful Execution Models, Harvard and von Neumann, run on nearly 100% of the computers available today.
This is more advanced, and is for inquisitive and curious readers
The Harvard architecture physically separates the apparatus for retrieving the instructions which make up an active program from that of the data access apparatus which the program accesses during execution.
Programs written for computers employing a Harvard architecture may perform up-to 100% faster for tasks which access the main memory bus. Note however that certain memory circuitry is necessarily larger for those who select a Harvard architecture.
The von Neumann architecture uses a two-step process to execute instructions. First, the memory containing the next instruction is loaded, then the new instruction just loaded is allowed to access this same memory as it executes; using a single memory for both program and data facilitates Meta-Programming technology like compilers and Self-modifying Code.
The von Neumann architecture was the first proposed model of computation and almost all real-world computers are von Neumann in nature.
Word-size is a primary factor in a computer's physical size.
In Minecraft, machines from 1-bit all the way up to 32-bits have been successfully constructed.
Common word-size combinations :
The amount of information a computer can manipulate at any particular time is representative of the computer's Data Word-size.
In Digital Binary, the computer's Data-Word size ( measured in bits ) is equal to the width or number of channels in the computers main bus.
Data-Words commonly represent integers or whole numbers encoded as patterns of binary digits.
The maximum sized number representable by a Binary encoded integer is given by 2Data-Word width in bits - 1.
For example, a computer with a Data-Word size of 8-bit will have eight channels on its bus (set of wires, connecting components) and therefore, we can count up to (28 - 1). 255. Counting further than 255 is not possible with eight bits, as the operation 255 + 1 carries over a one, which requires a ninth bit or what is called a binary overflow will occur, returning 0 as the answer, which is incorrect.
This is simply visualized;
Some common Integer data sizes are:
|Max Representable Number||Number of Bits Required|
|1 = (21 - 1)||1|
|7 = (23 - 1)||3|
|15 = (24 - 1)||4|
|255 = (28 - 1)||8|
|65535 = (216 - 1)||16|
|4294967295 = (232 - 1)||32|
Data-Word size also governs the maximum size of numbers which can be processed by a computer's ALU (Arithmetic and Logic Unit).
The amount of data a computer needs in order to complete one single instruction is representative of a computer's Instruction Word-size.
The Instruction-Word size of a computer is generally a multiple of its Data-Word size, This helps minimize memory misalignment while retrieving instructions during program execution.
This is a collection of instructions the Control Unit (CU) can decode, and then execute.
Instructions are essentially functions run by the computer, examples of instructions include:
- Add, subtract, multiply and divide
- Read/Write from RAM/ROM/tertiary memory
- load and unload data into the RAM
- Branching to other parts of the code
- Comparing registers
- Selecting a Logic function (NAND, NOR, NOT etc.)
Instructions can be programmed into the RAM, loaded from ROM or directly activated by using a lever or button. Each instruction would have its own specific binary string assigned to it (e.g. 0000=Load data from register 0001=add A and B 1011=Save RAM into tertiary memory etc.) and would probably require its own binary to decimal or binary to BCD to decimal encoders and buses to the ALU/registers.
Architecture of the Computer
Inside the computer, there is a Central Processing Unit (not to be confused with the Control Unit (CU), a component inside the CPU), which in real life, is a very small and powerful component which acts as more or less, the brain of the computer. In Minecraft, it is difficult to compact it to the scale we see in real life so don't worry if it looks wrong.
We will first be designing our 4-bit Central Processing Unit in the next chapter, as it is the most important thing in our computer with the Execution Model (the method of communication and organization of the CPU) in mind, (talked about in this page, before, in the Execution Model section) we can map out the construction of the computer.
The CPU follows a cycle four steps, fetch, decode, execute and (sometimes) stores to perform instructions. The CPU first fetches the instruction from RAM, decodes what it means (the instruction will most likely be a number, and the CPU must find out what number it is), and once it understands what the instruction is, it will perform that action. This sometimes requires for the data to be put back into the storage, therefore it will store the data. The cycle is then repeated.
There are five busses in the CPU, each to carry information from one component to the next. Busses are channels of redstone connecting each component. Since we are building a 4-bit computer, we only need four channels in our bus. These are the red and blue lines connecting the components inside the CPU. Notice that the blue buses have less than four lines, this is because they do not carry data. Since busses can only carry data one way (in Minecraft, due to repeaters only working one way), there are two buses connecting the CPU to the outer computer.
The first bus is the data bus, this is to transfer information from the storage or I/O devices to the CU. Instructions are also sent through this line The CU can also use this bus to transfer data to the ALU. The ALU cannot transfer data onto this bus because buses only work one way and once the information is taken by the ALU, the bus cuts off beyond the ALU. Information from the ALU is passed through bus 2.
The second bus is the data bus, but returns the data from the ALU to the CU. The CU cannot send data through this bus to the ALU because the bus goes from left to right and works in one direction only. The CU can send information back to the storage units though, and is used to set values of storage devices.
The third bus is the address bus, which the CU can send the address of storage. This is where the information resides. For example, the CU asks for the address of the byte living in 0001. It sends the address (0001) through the address bus and the RAM will return the value of the byte through the first bus. 0001 is the location of the byte, not the value of it.
The fourth bus is the control bus, which the CU will communicate with the RAM with. For example, one wire could tell the RAM to set the byte to the value to the data sent to it by the CU. Another wire could tell the RAM to get the byte from the address sent to it by the CU.
The fifth bus is another control bus, linking with the ALU, which sends flags from the ALU. Flags are notes which could be error messages. For example, the CU could ask the ALU to add 15 and 1 in a 4-bit system. Adding 15 and 1 in 4 bits would yield 0 (explained above) and this is called a binary overflow. This is an error and the ALU will tell the CU about this through the fifth bus as a flag. The CPU could also send data to the ALU and ask for it to perform an action with that data.
Control Unit (CU) will fetch instructions from the instruction ROM (for other computers, instructions can be changed and therefore is RAM. For our case, we are running a fixed program and do not need to change the instructions. This simplifies the process entirely and the instruction is Read-Only Memory (ROM)). Inside the CU, it will then decode the instruction, which is normally a number, into a sensible action. It will then perform that action and if the instruction requires, store the result into the RAM. It communicates with the RAM through the control bus and receives flags from the ALU. It can also ask the ALU to perform actions on data it sends to the ALU (e.g. addition). To communicate with the RAM, for example, one wire could tell the RAM to set the byte (the location of it is specified through the third, address bus) to the value to the data sent to it by the CU through the second, data bus.
Arithmetic Logic Unit (ALU) will execute instructions sent to it from the CU and will compare binary numbers and communicate with the Control Unit. It can do simple addition and subtraction which can be repeated to do multiplication and modulus (then division). There are also logic gates for booleans, the fundamental logic gates are required, such as the NOT gate and the NAND gate.
Now we can choose from a range of designs of busses, each contributing to the aforementioned three key designing goals of a Minecraft computer.
- The player may want to use mods or datapacks like WorldEdit and BlingEdit
- If you're in survival and don't have any repeaters you can use two Redstone torches
- Color code your computer (use blue wool/concrete for RAM, yellow for the ALU, etc.)
- Start small, and get the hang of small computers before you try more complex machines.
- Structure blocks can be very helpful for moving components around, and combining multiple components together. However, note that these cannot be obtained without using commands.
- Redstone circuit
- Redstone clock
- Logic circuit
- Memory circuit
- Pulse circuit
- Transmission circuit
- Tutorials/Advanced redstone circuits
- Tutorials/Redstone machines