<本站文本内容除另有声明外,转载时均必须注明出处。(详情…中文Minecraft Wiki是完全公开的。请勇于扩充与修正内容!Minecraft中文Wiki微博正在更新!或许有兴趣去看看想与其他用户进行编辑上的沟通?社区专页正是为此创建的。翻译或创建页面之前,不妨看看译名标准化Wiki条例页面。需要管理员的协助?在管理员告示板留言也许可以帮到您。>

教程/红石计算机

来自Minecraft Wiki
跳转至: 导航搜索
Clock JE2 BE1.gif
此条目需要更新。

条目中某些信息已经不符合当前版本情况。

此条目的内容需要改进。

这些内容因翻译质量较低而违反或未达到条目标准
你可以帮助我们来改进此条目。

Ic translate.svg
此条目的(部分)内容需要翻译。

你可以帮助我们来翻译此条目,但请勿使用机器翻译

本文在探讨Minecraft中计算系统的设计和实现。

第一节, 建造一台计算机的教程,这是一个关于如何在Minecraft中建造计算机以及如何扩展与改进的详细教程。不需要大量的计算机科学方面的知识。尚未完成

第二节, 设计一台红石计算机,提供了在Minecraft中设计与理解一个红石计算机的基本概念。不需要大量的计算机科学方面的知识。

目录

概述[编辑 | 编辑源代码]

计算机促进了人们通过编程来交流的想法的实现

这篇文章将会解释为在Minecraft中设计与建造计算机打下基础,假定读者相当了熟悉红石并且有基本水平的计算机知识。

 事实上在不了解计算机是如何工作的情况下是无法建造计算机的。此教程旨在解释你需要知道的所有内容,但这确实需要一点对计算机科学的了。我们将涉及的最深层次是IGCSE CS。

所有的计算机系统都至少有一个处理单元。在运行时,处理单元执行存储在计算机内存中的指令。为了使在Minecraft中建造计算机有一个良好的开始,你应该学习计算机科学。有非常多的资源与教程可以用来学习计算机科学。但是推荐观看Crash Course on Computer Science作为一个基础的开始。尤其是1-8节。即使它不够彻底,但可以做为你理解计算机的基础。

在Minecraft中,大多数计算机是由红石粉红石火把以及红石中继器组成的,以引起粘性活塞或者红石灯的变化。 它们是被一系列的按钮拉杆压力板等等所控制。另外一些想法(本文没有涉及)是利用漏斗矿车与红石。

第一节 '建造一台计算机的教程,这是一个关于如何在Minecraft中建造计算机以及如何扩展与改进的详细教程。不需要大量的计算机科学方面的知识,因为会对其解释,但会对其深入研究。

第二节 设计一台红石计算机,提供了在Minecraft中设计与理解一个红石计算机的基本概念。不需要大量的计算机科学方面的知识,因为会对其解释,但会对其深入研究。

实现[编辑 | 编辑源代码]

计算机可以被用在很多方面,从创造一个智能房子到运行一张冒险地图。但是,由于Minecraft对于计算机的限制(将会在下面说明),它们仍然是一个抽象概念,并且是一个理解CPU结构与嵌入式系统的良好工具。

计算机与计算器的区别在于计算器在没有用户输入时无法连续执行很多指令。计算机可以连续比较并处理指令来完成任务。

但是,在Minecraft中红石计算机非常慢并且臃肿,以致很难为它们找到实际应用。即使是最快的红石计算机也要花数秒来完成一个计算,并且占据数千方块的体积。在Minecraft中命令方块由于它们的速度以及清晰且高级的指令,所以相比于计算机有很大的优势, 有一些Mod可以改变计算机的速度,比如TickrateChanger 会改变游戏刻速率。

第一节, 建造一台计算机的教程[编辑 | 编辑源代码]

介绍与条件[编辑 | 编辑源代码]

红石的逻辑紧密地反映了二进制逻辑,应为红石可以是激活或非激活的,可以被解释为0或1.在本教程中,我们将提到基础的二进制逻辑与众多简单的计算机科学术语。这里有一篇文章,很好地解释了二进制以及如何转化到二进制。请读Architecture of building the Computer section一章因为接下来我们对于计算机的设计是基于此的。

这一章会关注于知识的运用与红石的操作,以来创造一台简单的8位计算机, 并且会解释如何建造以及它是如何工作的。

所有的主题被分为了(理论)与(实践)两部分。理论部分会深入解释会发生什么,而实践部分会说明如何在minecraft中建造,它应该是什么样子,以及可能的存档。

The computer we will be building (MASIC Computer)

Step 1: Memory and Address Decoders (THEORY) (NOT FINISHED)

Step 1: Memory and Address Decoders (PRACTICE)

Step 2: Building an Arithmetic Logic Unit (THEORY)

Step 2: Building an Arithmetic Logic Unit (PRACTICE) (NOT FINISHED)

Step 3: Instruction set and machine architecture (THEORY)

Step 3: Instruction set and machine architecture (PRACTICE) (NOT FINISHED)

在Minecraft中,为了让你的红石计算机最适合你手头的任务,需要有以下三个主要的设计目标。而有些得失需要进行考虑,比如当计算机的规模越大时,运行速度就会更慢,因为红石中继器的数量会随着距离的增加而增加。越多的内存,意味着速度就越慢,体积越大。

紧凑程度

这台计算机的规模有多小?在Minecraft中,设计一台生存模式的计算机很大可能会强调这一点。所需的重复次数将随着大小的增加而增加。

内存大小

它能容纳多少的内存?它可以计算多少数字和字节?这对于大规模的计算机来说是很重要的,如那些可以完成更复杂算法和更大规模指令集的计算机(例如说,计算平方根或是三角学)内存大小或者位体系结构越大,计算机越复杂。

速度/性能

它能以多快的速度执行操作呢?它是否达到了最大优化的程度以执行工作呢?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.

The MASIC Computer[编辑 | 编辑源代码]

The work in progress computer which we will be making in the tutorial. 8 bits, 16 bytes of RAM. I/O is a seven-segment display (for hex and decimal) and a control panel which we will make.

7-segment display

The MASIC computer aims to be a one-size-fits-all computer and does not specialize in one task, so it is fully programmable by reading its own memory (explained in Section 2: instruction sets). The simple I/O is great for multipurpose use and the memory is sufficiently sized. It runs at quite a fast speed (because of its small size).

Step 1: Memory and Address Decoders (THEORY)[编辑 | 编辑源代码]

Decoders convert binary figures into decimals. For example looking at the 8-bit decoder 00 turns on the first lamp which stands for 0. 01 turns on the second lamp which is 1. 10 turns on the third which is 2. 11 turns on the last one which is 3.

Step 1: Memory and Address Decoders (PRACTICE)[编辑 | 编辑源代码]

Address Decoder[编辑 | 编辑源代码]

0000 0000 (notice output 1 is lit)
0000 0001 (notice 2nd output is lit)
0000 0010
0000 0011

This is the design for the address decoder we are going to build.

B.png C.png

Above is a simple 2-bit state, so it has two inputs (left and right) through the repeaters. The output is the redstone line above which will turn OFF when the state is met. The state is whether the redstone input will turn OFF the redstone line above; if so, the state is the redstone inputs. In the above case, the left must be turned OFF (0) and the right (blue) must be turned ON (1) to yield an OFF on the top redstone line. So it expects a state of OFF ON (aka 01 for binary).

They are colored blue for bits which should be ON (1) for it to stop powering the top redstone line. Once every bit stops powering the redstone line, it then turns off.

These are basically either one or two NOT gates feeding into a OR gate and then NOT the output.


Screenshot 2019-07-15 at 10.19.28 am.png Big not.png

Above is an 8-bit state, it expects 8 inputs in exactly the order 0000 1101. So that state it expects is 0000 1101. So the redstone torches power the inputs, and so we see the redstone line on the top turns OFF (only when exactly three redstone torches are placed in that exact order of 0000 1101).

Now if we put multiple of these together, we can count up in binary with the blue bits to get all 255 states of 8 bits. The one below is 8 bits, and has four state expectations. See the right images to see it in action. Now each green output can be a memory cell, and if we continue counting in binary, it will reach 255.

Screenshot 2019-07-15 at 10.30.13 am.png

The input is 0000 0011 (see the redstone torches for input) and where the blue bits match the current state, the green output is ON.

  • 0000 0000 - first signal out (on the images on the right)
  • 0000 0001 - second signal out
  • 0000 0010 - third signal out
  • 0000 0011 - fourth signal out

So now we keep counting up in binary to get up to 0000 1111 and stop there; we should now have 24 (16) state expectors. Now we're done with the address decoder. We do not continue counting up to 1111 1111 because of instruction set limitations, explained in section 3: instruction sets

Step 2: Building an Arithmetic Logic Unit (THEORY)[编辑 | 编辑源代码]

The Arithmetic Logic Unit referred to as the ALU will compare and perform mathematical operations with 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 the topic 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 8-bit inputs

  • A + B (Add A to B)
  • A >> (bitshift A right (the same as binary divide by 2))
  • << A (bitshift A left (the same as binary multiply by 2))
  • NOT A (The opposite of A)

There can also be multiple ALUs inside a computer, as some programs require a lot of operations to run, which do not depend on the previous operations (so they can be threaded) so delegating them to different ALUs could significantly speed up the program.

binary adder

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.

full binary adder

All ALUs, to perform adding operations, require the presence of multiple adders. Every 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/Arithmetic logic 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 a 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 ends to test your creation. So 0010 + 0011 should yield 0101 (2 + 3 = 5, we are reading right not left).

Fractional numbers[编辑 | 编辑源代码]

A computer takes care of numbers less than one by form 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[编辑 | 编辑源代码]

An adder with all labeled parts.

The subtraction of numbers is surprisingly simple. The ALU first must change the second number (the value subtracting by) and convert it from a positive number to a negative number. A two's complement is when you invert the binary number (so that all the 0s are 1s and 1s are 0s) and add one to it.

Example: do 10 subtract 9

1. 0000 1001 (9 in binary, we want -9, not 9)
2. 1111 0110 (Invert 9, so that all 0s are 1s and 1s are 0s)
3. 1111 0111 add one (this the two's complement of 9)
4.
0000 1010 (10 in binary)
+1111 0111 add two's complement of 9 (aka -9)
----
0000 0001 result (10 + (-9) = 1) (there is an overflow, this just means that the result is not a negative number)

This poses the complexity of signed numbers.[1] This is a weight to the binary number to assign it as a positive or negative number. Whether the result is a negative or positive number is determined by the overflow flag. If there is an overflow, this means that the number is positive and otherwise, negative.

To implement this, you can ask the ALU to do 3 operations. To do A subtract B, the operations are

Operation: A SUB B

  • NOT B
  • (set B to) B ADD 1
  • (set A to) A ADD B
  • RETURN A

Multiplying two numbers[编辑 | 编辑源代码]

Multiplication is repeated addition, so the easiest (inefficiently) is to add A to a variable B amount of times.

Here's pseudomachine code for it

Operation: A * B

  • C = 0
  • (set C to) C ADD A
  • (set B to) B SUB 1
  • JUMP IF (B > 0) TO LINE 2
  • RETURN C

However, there are more efficient ways of multiplication. A good method is to repeatedly bitshift the first number to the location of each 1 in the second number and sum it.

There are underscores to mark indents, since padding with 0s are less intuitive. subscript 2 means in binary, and decimal numbers are also in bold

__ __11 3 (notice that there are 2 1s)
x_ 1011 11
----
__ __11 We shift 112 by 010 since the 1st bit of 10112 is 12
+_ _110 We shift 112 by 110 since the 2nd bit of 10112 is a 12
+1 1000 We shift 112 by 310 since the 4nd bit of 10112 is a 12
---- the 3rd bit of 10112 is 02 so we do not add a 112 there
10 0001 33 (result)

so this is more efficient for larger numbers.

Operation: A * B

  • C = 0
  • D = 0
  • (Set A to) << A (bitshift A to the left)
  • JUMP IF (BIT (D) OF B == 0) TO LINE 6
  • (Set C to) C ADD A
  • (Set D to) D ADD 1
  • JUMP IF (D < LENGTH OF B) TO LINE 3
  • RETURN C

Don't forget that

<< A (bitshift to the left) is effectively, A * 2

and

>> A (bitshift to the right) is effectively, A / 2

If the numbers are predictable or the CPU must do a lot of similar numbers in bulk, consider using a look-up table to quickly get results to frequently called multiplication. Is this a way of hard-coding your answers and is used in extreme cases.

Step 2: Building an Arithmetic Logic Unit (PRACTICE)[编辑 | 编辑源代码]

1bitALU-layer0-6.png

Step 3: Instruction set and machine architecture (THEORY)[编辑 | 编辑源代码]

This is pretty fun, this part.

Elaborating on Chapter 2: Instruction Set, we will be creating one for ours.

For the MASIC Computer, the computer which we are building, have an 8-bit system, so that means each instruction on each slot of the stack memory will be 8 bits. The stack memory is the memory where any information can be stored and is on the RAM. There will be a counter, called the program counter, which increments by 1 every cycle. A cycle is the CPU fetching the instruction, decoding the instruction (finding out what to do with the instruction) and executing the instruction (doing what it tells it to do). Then it moves on to the next one by incrementing the program counter and reading the information at that location in the stack memory.

So each byte in the stack memory has 8 bits for us to work with.

0000 0000

and some instructions require an address, say loading memory into a register so that we can perform operations (such as addition) on it. Each instruction will be split into two parts, each 4 bits. The first is the TYPE. the TYPE will specify what the computer must do and the ADDRESS will be where the value we will perform our operations are located.

OPCODE OPERAND

so 4 bits for the TYPE, we can have 2^4 types, so 16 different ones. Our computer will have two registers, so one bit will be for specifying the register the operation will executing on and is denoted by an x.

Instructions are put in the same place as memory and as the ADDRESS part of the instruction is only four bits, we can only reference memory from 1-16 lines, requiring some clever programming to fit larger programs. Memory is also limited to 16 bytes per program. Values and instructions are essentially the same thing, so if you write an instruction to store it onto a line that previously-stored an instruction, that effectively overwrites the instruction with a value. Accidental execution of values might be a problem, so a STOP command must be used to prevent any errors. This is a whole lot to understand, so good sources are https://www.computerscience.gcse.guru/theory/high-low-level-languages and https://scratch.mit.edu/projects/881462/ <-- really helpful actually. and also don't forget to take both CS and ICT for your IGCSEs.

Prerequisites[编辑 | 编辑源代码]

The section will cover simple topics and components commonly found in a computer, so information from chapter 2 will be used, such as the ALU, RAM, registers and binary manipulation.

The MASIC Instruction Set[编辑 | 编辑源代码]

Since the computer Here is the first draft of the instruction set, with only essentials. This is based on other assembly languages, but changed to adapt to our architecture. There are two registers, so we need instructions to perform operations on both registers.

BINARY OPCODE COMMENT
0000 LOAD R1 Load the ADDRESS into register 1
0001 STORE R1 Store contents of register 2 into ADDRESS
0010 JUMP R1 IF Jump to line ADDRESS if register 1 is equal to 0
0011 ADD R1 Add contents at ADDRESS to register 1
0100 <<R1 Bitshift register 1 left
0101 NOT R1 Bitwise NOT register 1
0110 JUMP Jump to line OPERAND
0111 STOP Terminate the program.
1000 LOAD R2 Load the ADDRESS into register 2
1001 STORE R2 Store contents of register 1 into ADDRESS
1010 JUMP R2 IF Jump to line ADDRESS if register 2 is equal to 0
1011 ADD R2 Add ADDRESS to register 2
1100 <<R2 Bitshift register 2 left
1101 NOT R2 Bitwise NOT register 2
1110 OUT R1 Outputs register 1
1111

To translate:

1000 0011 means LOAD R2 3 because LOADR2 is 1000 and 0011 is 3.

These can be in a process so that functions can be performed.

Writing programs[编辑 | 编辑源代码]

This one does the Fibonacci sequence: (0,1,1,2,3,5,8... etc.)

FIBONACCI
LINE BINARY INSTRUCTION COMMENT
1 0000 1110 LOAD R1 14 set register 1 to 0 (the value at line 14)
2 0011 1111 ADD R1 16 add the value at line 16
3 1110 0000 OUT R1 output the register
4 0001 1111 STORE R1 16 put that in line 16
5 0011 1110 ADD R1 15 add the value at line 15
6 1110 0000 OUT R1 output the register again
7 0001 1110 STORE R1 15 now put the output back
8 0110 0010 JUMP 2 we don't have to reset the register so we loop back to line 2.
...
14 0000 0000 0
15 0000 0001 1
16 0000 0001 1

The previous is an example of a low-level assembly language. If it was written in a high level language such as C++, it would look more like this:

#include <iostream>
using namespace std;
int main()
{
    int n, t1 = 0, t2 = 1, nextTerm = 0;
    cout << "Enter the number of terms: ";
    cin >> n;
    cout << "Fibonacci Series: ";
    for (int i = 1; i <= n; ++i)
    {
        // Prints the first two terms.
        if(i == 1)
        {
            cout << " " << t1;
            continue;
        }
        if(i == 2)
        {
            cout << t2 << " ";
            continue;
        }
        nextTerm = t1 + t2;
        t1 = t2;
        t2 = nextTerm;

        cout << nextTerm << " ";
    }
    return 0;
}

Instruction Cycle[编辑 | 编辑源代码]

Rounded squares are components, squares are registers. Green arrows are busses

The instruction set is the lower assembly language, so we want to integrate that more with the hardware side. This revolves around the fetch-decode-execute cycle (explained above). In the CPU, there will be 4 important registers,

the Program Counter (PC), keeps track of which program the computer is currently on

the Memory Address Register (MAR), keeps track of where the next memory location will be

the Memory Data Register (MDR), keeps track of what the memory AT the location is

the Current Instruction Register (CIR), keeps track of what instruction is currently being worked on

and the ALU Accumulator (ACC). keeps track of the input and output from the ALU

There are also four components to keep in mind, the Address Decoder, the memory, the Instruction Decoder and the ALU.


FETCH The program will get the next instruction.

  1. PC sends the instruction number to the MAR
  2. PC increments by 1, to prepare for the next instruction
  3. Address Decoder decodes the address, and requests information at that address from the memory
  4. MDR receives the requested information (in the case of the picture, if the MAR is 0001, it receives 'LOADR1 1')

DECODE The program will identify what the instruction is

  1. CIR receives the information from the MDR, through the information flow
  2. Instruction Decoder decodes the instruction and what to do

EXECUTE The program will execute the instruction

  1. In the case of the picture, the program receives 'LOADR1 1' as the instruction, the Instruction Decoder splits the instruction up into the opcode and the operand.

The opcode is 'LOADR1' and the operand is '1'.

  1. Operand is sent to the MAR, to get the information at that address
  2. MDR receives the information at that address (in the example, it is the same line)

Now four things could happen depending on what the instruction is.

If the instruction is an ADD instruction, the ACC will be told to receive the information from the information flow and the ALU will perform operations on it, outputting it to the ACC again.

If the instruction is a LOAD instruction, the CU will load the instruction to the register.

If the instruction is a STORE instruction, the CU will instead SET the data at the location specified by the MAR in the memory.

If the instruction is a OUT instruction, the CU will send the instruction to the output peripheral.

REPEAT The instruction cycle repeats itself until it reaches a STOP instruction or runs out of memory

Step 3: Instruction set and machine architecture (PRACTICE)[编辑 | 编辑源代码]

红石计算机的规划[编辑 | 编辑源代码]

当设计一个计算机,设计结构会影响整个红石计算机。规模和性能取决于计算机的组成。

一些事情需要考虑:

  • 执行模型(内存的计算机组织与程序存储和执行)
  • 字节大小(信息的大小,你的红石计算机用这些执行命令)
  • 命令集(红石计算机的一个结构)
  • 内存大小(数据可以存储在内存中,可存储数据多少取决于内存大小)


有一个选择决定将提供强有力的指导在各种组件的设计你的电脑。

执行模型[编辑 | 编辑源代码]

命令存储块的技术叫做程序在内存是允许计算机同时执行各种不同的任务。使用的设备由计算机来存储和检索这些程序是计算机的执行模型。世界上最成功的两个执行模型,哈佛和冯·诺依曼,今天将近100%的可用的计算机上运行。

哈佛结构[编辑 | 编辑源代码]

The Harvard architecture 检索器分离的命令组成一个活跃的程序从数据访问器的程序在执行期间访问。   编写的程序对电脑使用哈佛架构可能执行的任务达到快100%访问主内存总线。但是要注意,哈佛架构的某些记忆电路体积会很大。

冯·诺依曼结构[编辑 | 编辑源代码]

The von Neumann architecture使用一个两步的过程来执行命令。首先,加载内存包含下一个命令,然后新命令加载是允许访问相同的内存,因为它执行,使用一个内存的程序和数据促进元编程技术像编译器和自我修改代码。    冯诺依曼体系结构是第一个提出模型的计算和几乎所有真实的计算机是冯·诺依曼在《自然》杂志上。

位宽与指令位数[编辑 | 编辑源代码]

位数大小是计算机物理尺寸的主要因素。 在Minecraft中,从1位一直到32位的机器已经被成功构建出来。 常见的字大小的组合:

数据 命令
4 8
8 8
8 16
16 16

数据字符[编辑 | 编辑源代码]

计算机在任何特定时间可以操作的信息量代表了计算机的数据字大小。

在数字二进制中,计算机的数据字大小(以位为单位)等于计算机主总线中通道的宽度或数目。

数据字通常表示整数,或编码为二进制数字模式的整数。

最大大小的数量可表示的二进制整数编码是2 ^数据字宽度在位- 1。

一些常见的整数数据大小是:

最大可表示的数量 所需的字节数
1 ( 2 ^ 1 - 1 ) 1
7 ( 2 ^ 3 - 1 ) 3
15 ( 2 ^ 4 - 1 ) 4
255 ( 2 ^ 8 - 1 ) 8
65535 ( 2 ^ 16 - 1 ) 16
4294967295 ( 2 ^ 32 - 1 ) 32

数据字大小还决定了可以由计算机的ALU(算术和逻辑单元)处理的数字的最大大小。

命令字[编辑 | 编辑源代码]

计算机完成一条命令所需的数据量代表计算机命令字大小。

计算机的命令字大小通常是其数据字大小的背书,这有助于在程序执行期间检索命令时最小化存储器未对准。

计算机的设计[编辑 | 编辑源代码]

命令集架构[编辑 | 编辑源代码]

状态[编辑 | 编辑源代码]

内存是一系列的位。在Minecraft中,尽管曾经成功创造过32位和64位[2]计算机,但是通常情况下内存占8位或16位。每一位都是两种可能的状态中的一种:开或闭。而内存就是一系列的开和闭,用于完成特定的任务。

信号[编辑 | 编辑源代码]

现实世界计算机使用二进制,一系列的1和0。“1”表示“开”和“0”表示“关”。在"Minecraft,最好的体现是红石:有信号意味着“1”,没有信号表示“0”。然而,根据距离红石从内存存储,它是“0”可以是任何信号强度从0到14。你也可以设计,使“1”信号强度从1到15。

[编辑 | 编辑源代码]

我们常规的十进制是一种以10为基数的数字系统。在电脑中使用的数制——二进制,则是以2为基数。为了比较两者,我们看一下两位数。在十进制中,左边的那一位是十位。在二进制中,则是“二位”。比如在十进制中,“10”表示“十”。而在二进制中,“10”表示“二”。有两种常用的十进制转二进制的方法:

最高位优先:这种方法需要一点直觉。我们以42为例。首先我们找(小于等于42的)最大的2的幂(“2的幂”就是如32 [2^5] 或65536 [2^16])。在这个例子中,是32。然后我们用例子中的数字来减它,42-32=10。那么最左边的一位就是“1”。随后我们继续找下一个2的幂,看它是否小于等于当前的数字。对于这个例子来说,下一个是16,16并不比10小,所以接下来这一位是“0”。一直找下去直到数字为0为止。无论二的幂是小于还是等于当前的数字,都要减掉它,并且记下一位为“1”。否则下一位就是“0”。就我们的例子来说接下来就是 8<10-->10-8=2-->"1" 4>2-->"0" 2=2-->2-2=0-->"1" 1>0-->"0" 因此最终42的二进制表示就是“101010”。不错。

最后是最低位:这个方法不需要记忆许多2的指数。相反,它重复将数字除以2,使用商作为下一个被除数,余数作为二进制位。 但请记住,此方法从右到左写入二进制数,而不是像前一种方法一样从左到右写入。 让我们重用我们的例子,42: 42/2=21 r 0 (最右边的数字是0) 21/2=10 r 1 (向左边一位的数是1) 10/2=5 r 0 (向左边一位的数是0) 5/2=2 r 1 (向左边一位的数是1) 2/2=1 r 0 (向左边一位的数是0) 1/2=0 r 1 (向左边一位的数是1)

商数为0,所以我们停止。 这给了我们二进制数“101010”。与之前的方法相同。

过渡[编辑 | 编辑源代码]

[编辑 | 编辑源代码]
命令[编辑 | 编辑源代码]

功能本质上是由计算机命令构成的,命令的例子包括:

  • 加、减、乘、除
  • 从RAM/ROM/第三存储器的读/写
  • 读取和写入数据到内存
  • 分支的其他部分代码
  • 比较寄存器
  • 计算一个逻辑函数 (NAND,NOR,NOT etc.)

命令可以被编程到内存,从ROM加载或直接通过一个拉杆或按钮激活。每条命令都有它自己的特定的二进制串分配(比如0000=从寄存器加载数据,0001=A加B,等),并且可能需要其自己的二进制到十进制或二进制到BCD到十进制编码器和总线到ALU或寄存器。

归类[编辑 | 编辑源代码]

抽象[编辑 | 编辑源代码]

映射[编辑 | 编辑源代码]

符号[编辑 | 编辑源代码]
数字[编辑 | 编辑源代码]

符号可以用红石灯或者活塞的推拉方块产生凸凹起来显示:

注:如果用红石灯的话不要用黄色的方块做面板,不然不容易分辨。

功能[编辑 | 编辑源代码]

形式化[编辑 | 编辑源代码]

可计算性[编辑 | 编辑源代码]
变量[编辑 | 编辑源代码]

变量是数字、字符串、字符(套)或布尔值(真/假)存储在RAM中的空间。例如,布尔值可以用来保存信息如果程序已经达到某种状态。以下信息需要保存一个变量:名称,类型(数字、字符串或布尔),和变量值。变量,顾名思义,改变。命令操作可以改变变量。在运行程序时创建变量,一旦程序结束,变量值会被从内存中删除。当一个程序重启,变量会被重置。


层次结构[编辑 | 编辑源代码]

内存[编辑 | 编辑源代码]

内存是储存您的程序数据的地方。 它是可更改的 (但它在计算机关闭后将会被删除),它也用于储存您计算机的数据。例如说,在一个从1开始计算的程序中,1就被储存在了内存中,从内存中加载出来的1被添加上原来的1便得到了2。

执行[编辑 | 编辑源代码]

语义[编辑 | 编辑源代码]

数据[编辑 | 编辑源代码]

数据是计算机处理的信息,使用二进制表示。

控制单元(CU)[编辑 | 编辑源代码]

机器架构[编辑 | 编辑源代码]

数据通道[编辑 | 编辑源代码]

Processing[编辑 | 编辑源代码]

算术逻辑单元(简称ALU)[编辑 | 编辑源代码]

1-bit 3 function ALU.png

ALU是计算机最重要的组件之一,在现实生活和Minecraft中。首先,你必须选择你希望能够实现的功能。大多数时候,这些都是加法、减法和一组逻辑选项。

与,或,与非,或者你所喜欢的。你必须建立单位和所有你想要的逻辑门和数学函数和选择哪一个的输出显示。

(数据)总线[编辑 | 编辑源代码]

用总线允许您的计算机的组件相互通信。

一条总线可以通过使用创建红石布线连接你的计算机的运算器,随机储存器,只读储存器,中央处理器和寄存器在一起,这样他们就可以互相之间发送数据。通常是重要的计划,建立你的电脑的组件,否则你创建总线过长,或者更糟的是,没有空间来创建总线,在这种情况下,您可以删除的组件并重建一个适当的位置,或者使用像WorldEdit移动组件到其他地方。

存储[编辑 | 编辑源代码]

Register

随机存取存储器[编辑 | 编辑源代码]

4byteRAM default.png

随机存取存储器又称RAM,是程序使用的一种存储器,具有易失性。易失性是指当电源断开时,它将丢失信息。大多数情况下,在Minecraft中内存数据不会失去,所以最简单的方法就是使用d-触发器来添加读写功能。

二级存储器[编辑 | 编辑源代码]

这相当于HDD和SSD。下面介绍一种非常紧凑的存储技术,要涉及到红石比较器,能够存储高达1KB的实际数据大小。

https://www.youtube.com/watch?v=1zE_XZLTDBw

三级存储器[编辑 | 编辑源代码]

第三,也是最后一点,是第三级内存,它需要大量的时间来读/写,牺牲速度但可以存储大量信息。在现实世界中,三级存储器使用的是一种老式的挂载内存的机制,而且现在也很少使用了。在Minecraft中,这种系统要用潜影盒来完成,潜影盒中的方块必须由排序系统进行排序,以表示某种形式的数据。由于这些工作需要大量的比较器和大量的时间,所以读/写速度相当慢。然而,利用某些mod可以加快游戏tick的速度并消除这个问题。这用于存储长期数据,这些数据需要在程序开始时加载。相当于一台真正的计算机的机械硬盘或固态硬盘。

机器状态[编辑 | 编辑源代码]

程序计数器[编辑 | 编辑源代码]

程序计数器用于告诉CPU应该运行哪行代码。在每个时钟周期,解码器将访问这个计数器来获取下一个要执行的命令。一些命令会比另一个访问不同的数据量,或任何数据,因此解码器将适量增加程序计数器的下一个命令。使用的计数器也跳转命令控制程序流。   

控制路径[编辑 | 编辑源代码]

处理[编辑 | 编辑源代码]

控制单元[编辑 | 编辑源代码]

Redstone Computer Control Unit.PNG

总线[编辑 | 编辑源代码]

Redstone Computer Control Busing.PNG

硬盘[编辑 | 编辑源代码]

Redstone Computer Tertiary Memory.PNG

固体方块可以被红石中继器强冲能,强充能方块可以点亮周围的红石粉。透明方块却不可以被冲能,这就是一个简单的硬盘。

程序内存[编辑 | 编辑源代码]

Redstone Computer Program Memory.PNG

程序内存,最基本,ROM(只读存储器)。ROM是最常用的远程执行一系列任务(如一个程序,因此得名)。它可以用来在用户控件(如图片)或每一行之间的时钟和足够的延迟2不是在同一时间。最简单、最高效的设计之一是一个图中,这可能是也可能不是加上解码器。它可以很容易地扩大,这是另一个优势。

机器状态[编辑 | 编辑源代码]

Redstone Computer Machine State.PNG

程序计数器[编辑 | 编辑源代码]

Redstone Computer Program Counter.png

时钟[编辑 | 编辑源代码]

Redstone Computer Clock.PNG

时钟同步组件或使用时间。(Minecraft)在大多数情况下,可以避免使用但有时它是计算机的功能所必需的。它基本上可以由红石火把链接成一条线/圈的非门(奇数建议或者你的输出必须“取反”),或者中继器,如上图所示。

提示[编辑 | 编辑源代码]

  • 你也可以使用一些像是WorldEdit的模组
  • 如果你在生存模式没有太多的红石中继器 你可以用两个红石火把代替
  • 利用颜色进行分区(例如用蓝色羊毛建造RAM(随机存取存贮器),黄色羊毛建造ALU(算术逻辑部件运算器)等)