After the assembly language is created it is necessary to determine how to represent each instruction as a number. |
在创建汇编语言后,有必要确定如何将每条指令表示为一个数。 |
This establishes a one-to-one correspondence between each instruction in the assembly language and each instruction code in the set of instruction codes. |
这将在汇编语言中的每条指令和指令代码集中的每条指令代码之间建立一对一的对应关系。 |
Converting a program from assembly language to instruction codes is called assembling, and conversion from instruction codes back into assembly language is called disassembling. |
将程序从汇编语言转换为指令代码称为汇编,将指令代码转换回汇编语言称为反汇编。 |
Several choices we must make at this point are: |
在这一点上,我们必须做出以下几个选择: |
What number is used to represent each assembly language instruction? |
每个汇编语言指令用什么数表示? |
How are instruction operands encoded? |
指令操作符如何编码呢? |
Are operands part of the instruction word (remember, by word I mean number), or are they separate words (numbers)? |
操作符是指令词的一部分(记住,这里的词我指的是数),还是单独的词(数)? |
First, to answer the last question, since there are only small numbers of instructions and registers in this VM it should not be very difficult to encode all operands in a single instruction word, even if (for the sake of simplicity) I were to use a 16-bit instruction word. |
首先,要回答最后一个问题,因为这个虚拟机中只有少量的指令和注册表,所以在一个指令词中对所有操作符进行编码应该不是很困难,即使(为了简单起见)我使用的是16位指令字符。 |
Thus, a 16-bit number written in hexadecimal has 4 digits, giving us easy access to 4 information fields, each containing 16 variations (0-9 and A-F). |
因此,用十六进制写的16位数有4位数字,使我们能够轻松访问4个信息字段,每个字段包含16个字符(0-9和a-F)。 |
The first digit of a machine word will be the instruction number. |
机器词的第一位数字将是指令编号。 |
This gives our VM the potential for having up to 16 different instructions. |
这使我们的虚拟机有可能拥有多达16条不同的指令。 |
This is a small amount by contemporary standards, but it is plenty for our example virtual machine. |
以现在的标准来看,这是一个小数目,但对于我们的示例虚拟机来说已经足够了。 |
The next three digits will be used for the operands. |
接下来的三位数字将用于操作符。 |
These can be used as three 1-digit operands, two operands of 1 and 2 digits, or a single 3-digit operand. |
它们可以用作三个1位操作符、两个1位和2位操作符或一个单独的3位操作符。 |
Having made these decisions, let us now establish the encoding. |
做出这些决定后,让我们现在建立编码。 |
Recall that we have 16 instruction numbers available. |
回想一下,我们有16个指令编号可用。 |
The halt instruction will be instruction 0, and there is an important reason for choosing 0 for this instruction. |
halt指令将是指令0,为这个指令选择0有一个重要原因。
|
Since empty space in the computer's memory will most likely be filled with 0s, any run-away program will eventually encounter a 0 and attempt to execute this instruction, immediately halting the program. |
由于计算机内存中的空白空间很可能都是被0填满的,任何失控的程序最终都会遇到0,并试图执行此指令,立即停止程序。 |