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. |
首先,我们来回答最后一个问题,既然此 VM 中只有少数指令和寄存器,将所有操作数编码到同一个指令词中并不会很难,即便(为简明起见)我要使用的是 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. |
这使得我们的 VM 最多能够容纳 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. |
它们可以是三个一位操作数,两个一位和两位操作数或者一个三位操作数。 |
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. |
终止指令为指令 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 并试图执行该指令,从而立即暂停该程序。 |