Asm Craft
本模组由 sally4953 制作。
本模组遵循 MIT 开源协议。你可以通过 GitHub 仓库查看其源代码:
本模组允许你在 Minecraft 中编写汇编语言程序并运行它们。
目前,本模组仅支持 Minecraft 汇编语言。C++ 编译器仍在开发中。
但我会尽力完成 C++ 编译器的实现。
为了使汇编应用程序可执行,我在 Minecraft 中实现了一个虚拟机(VM)。它使用了一套完全不同的框架。因此,让我为你展示具体信息:
虚拟机信息
寄存器
共有 7 个寄存器。前四个在调用函数时用作变量。另一个寄存器存储程序执行的指针(指向内存中的地址,指示当前正在执行的语句),还有一个用于存储函数返回值。最后一个寄存器是条件判断的结果,只有两种状态。
内存
虚拟机中有两块内存。一块用于存储应用程序的命令,大小为 1024 字节。因此,每个应用程序的大小不应超过 1024 字节(但我认为没有人会写出这么大的应用程序)。另一块内存用于存储运行时数据,大小也是 1024 字节。我认为 1024 字节的内存足以满足大多数玩家(或程序员)的需求。
指令
虚拟机目前仅支持 22 条指令。下表将向你展示相关信息。
| 名称 |
注释 |
长度(字节) |
| nop |
空操作命令。 |
1 |
| ret |
函数返回命令。 |
1 |
| mov A, B |
将 B 赋值给 A。 |
5 |
| sub A, B |
从 A 中减去 B。 |
5 |
| mul A, B |
将 A 乘以 B。 |
5 |
| div A, B |
将 A 除以 B。 |
5 |
| jmp A |
直接跳转到地址 A。 |
3 |
| cjp A |
如果最后一个寄存器的值为真,则跳转到地址 A。 |
3 |
| grt A, B |
如果 A 大于 B,则将最后一个寄存器设为真(否则为假)。 |
5 |
| lst A, B |
如果 A 小于 B,则将最后一个寄存器设为真(否则为假)。 |
5 |
| equ A, B |
如果 A 等于 B,则将最后一个寄存器设为真(否则为假)。 |
5 |
| cal A |
调用函数 A(A 为内存中的地址或标签)。 |
3 |
| ccl A |
如果最后一个寄存器的值为真,则调用 A(A 为内存中的地址或标签)。 |
3 |
| and |
仅当第一个和第二个寄存器的值都为真时,才将最后一个寄存器设为真(否则为假)。 |
1 |
| or |
仅当第一个和第二个寄存器中至少有一个值为真时,才将最后一个寄存器设为真(否则为假)。 |
1 |
| xor |
仅当第一个和第二个寄存器的值不同时(一个为真,另一个为假),才将最后一个寄存器设为真。 |
1 |
| not |
反转最后一个寄存器的值。 |
1 |
| inc A |
将 A 加一。 |
3 |
| dec A |
将 A 减一。 |
3 |
| neg A | 将 A 的相反数存储到 A 中。 | 3 |
| int A | 中断,请求虚拟机调用内存中编号为 A 的函数,等待执行完成,虚拟机随后会将结果值设置到寄存器 5 中。有关支持的中断信息,请参阅下表。 | 2 |
中断指令
虚拟机仅支持 12 种中断命令。下表展示了这些中断指令:
| 代码 |
注释 |
| 0 |
退出程序。 |
| 1 |
在快捷栏上方打印一个整数。 |
| 2 |
在快捷栏上方打印一个字符。 |
| 3 |
将世界时间设置为寄存器 0 的值。 |
| 4 |
将世界时间赋值给寄存器 5。 |
| 5 |
以寄存器 0 的值作为种子,生成一个随机数并赋值给寄存器 5。 |
| 6 |
将玩家分数设置为寄存器 0 的值。 |
| 7 |
将玩家分数赋值给寄存器 5。 |
| 8 |
将玩家生命值设置为寄存器 0 的值。 |
| 9 |
将玩家生命值的十倍赋值给寄存器 5。 |
| 10 |
分别将玩家的 X、Y、Z 轴坐标设置为寄存器 0、寄存器 1 和寄存器 2 的值的十分之一。 |
| 11 |
如果寄存器 0 的值为 0,则将玩家 X 轴坐标的十倍赋值给寄存器 5;如果为 1,则将玩家 Y 轴坐标的十倍赋值给寄存器 5;如果为 2,则将玩家 Z 轴坐标的十倍赋值给寄存器 5;否则,寄存器 5 保持为 0。 |
本模组对中文有更好的支持。因此,如果您不熟悉中文,可能需要使用翻译工具。
以上就是本模组的全部内容。无论如何,祝您玩得开心!
Asm Craft
The mod is made by sally4953.
This mod is licensed under the MIT open-source agreement. You can view its source code through the GitHub repository:
This mod enables you to write programs in assembly language within Minecraft and run them.
At present, the mod just support Minecraft Assembly Language. C++ compiler is still in the process of implementing.
But I will try my best to complete the C++ compiler.
For making the assembled application executable, I implemented a virtual machine(VM) in Minecraft. It uses a completely different framework. So, let me show you the specific information:
Virtual Machine Information
Registers
There are 7 registers. The first four are used as variables when calling a function. Another register stores the pointer for program execution (pointing to the address in memory, indicating the current executing statement), and there is one for storing the function return value. The last register is the result of the condition judgment, with only two states.
Memories
There are two memories in the VM. One is to store the application's commands. Its size is 1024 bytes. So every application shouldn't be more than 1024 bytes ( but I think no one can write such application ). The other memory is to store runtime data. Its size is also 1024 bytes. I think 1024-byte memory is enough for the most players (or programmers).
Commands
The VM supports only 22 commands at present. The following table will show you the information.
| Name |
Comment |
Length(byte) |
| nop |
Do-nothing command. |
1 |
| ret |
Function return command. |
1 |
| mov A, B |
Assign B to A. |
5 |
| sub A, B |
Subtract B from A. |
5 |
| mul A, B |
Multiply A by B. |
5 |
| div A, B |
Divide A by B. |
5 |
| jmp A |
Direct jump to A. |
3 |
| cjp A |
Jump to A if the last register is true. |
3 |
| grt A, B |
If A is greater than B, the last register is true (otherwise not true). |
5 |
| lst A, B |
If A is less than B, the last register is true (otherwise not true). |
5 |
| equ A, B |
If A is equal to B, the last register is true (otherwise not true). |
5 |
| cal A |
Call function A (A is the address in memory or a label). |
3 |
| ccl A |
Call A if the last register is true (A is the address in memory or a label). |
3 |
| and |
Set the last register to true if and only if the values in the first and second registers are both true (otherwise false). |
1 |
| or |
Set the last register to true if and only if one of the values in the first and second registers is true (otherwise false). |
1 |
| xor |
Set the last register to true if and only if the values in the first and second registers are not the same (true or false). |
1 |
| not |
Reverse the last register's value. |
1 |
| inc A |
Add one to A. |
3 |
| dec A |
Subtract one from A. |
3 |
| neg A |
Store the opposite number of A in A. |
3 |
| int A |
Interrupt, request the virtual machine to call the function with the number A in memory, wait for completion, and the virtual machine will set the value to the register 5. For the information of the supported interruptions, view the following table. |
2 |
Interruptions
The VM supports only 12 interrupt commands. The following table will show you the interruptions.
| Code |
Comment |
| 0 |
Exit. |
| 1 |
Print a integer above the hotbar. |
| 2 |
Print a character above the hotbar. |
| 3 |
Set the world time to the register 0's value. |
| 4 |
Set the register 5's value to the world time. |
| 5 |
Take the register 0 as the seed and generate a random number to the register 5. |
| 6 |
Set the player's score to the register 0's value. |
| 7 |
Set the register 5's value to the player's score. |
| 8 |
Set the player's health to the register 0's value. |
| 9 |
Set the register 5's value to ten times the player's health. |
| 10 |
Set the X, Y, and Z axis positions of the player to 1/10 of the register 0, register 1, and register 2's values respectively. |
| 11 |
If the register 0's value is 0, set the register 5 to ten times the player's X-axis position; if it is 1, set the register 5 to ten times the player's Y-axis position; if it is 2, set the register 5 to ten times the player's Z-axis position; otherwise, R5 remains 0. |
This mod has better support for Chinese. Therefore, if you are not familiar with Chinese, you may need to use a translator.
The above is all the content of this mod. Anyway, enjoy it!
评论 0
登录后参与评分
还没有评论,来抢沙发吧