| After the assembly language is created it is necessary to determine how to represent each instruction as a number. |
After creating the assembly language, 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. |
This establishes a direct correspondence between each instruction in the assembly language and each instruction code in the instruction set. |
| Converting a program from assembly language to instruction codes is called assembling, and conversion from instruction codes back into assembly language is called disassembling. |
Converting a program from assembly language to instruction codes is called assembling, and converting instruction codes back into assembly language is called disassembling. |
| Several choices we must make at this point are: |
At this point, we need to make some decisions: |
| What number is used to represent each assembly language instruction? |
Which number will be used to represent each instruction in the assembly language? |
| How are instruction operands encoded? |
How are the instruction operands encoded? |
| Are operands part of the instruction word (remember, by word I mean number), or are they separate words (numbers)? |
Are the 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. |
First, to answer the last question, since there are only a small number of instructions and registers in this virtual machine, it should not be very difficult to encode all operands in a single instruction word, even if (for simplicity) I use a 16-bit instruction word. |
| 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). |
Thus, a 16-bit number written in hexadecimal has 4 digits, which gives us easy access to 4 information fields, each containing 16 variations (0–9 and A–F). |
| The first digit of a machine word will be the instruction number. |
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. |
This gives our virtual machine the possibility of having up to 16 different instructions. |
| This is a small amount by contemporary standards, but it is plenty for our example virtual machine. |
This is a small amount by today’s standards, but it is enough for our example virtual machine. |
| The next three digits will be used for the operands. |
The next three digits will be used as operands. |
| These can be used as three 1-digit operands, two operands of 1 and 2 digits, or a single 3-digit operand. |
These values 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. |
With these decisions made, let us now establish the encoding. |
| Recall that we have 16 instruction numbers available. |
Remember that we have 16 available instruction numbers. |
| The halt instruction will be instruction 0, and there is an important reason for choosing 0 for this instruction. |
The halt instruction will be instruction 0, and there is an important reason for choosing 0 for this instruction. |
| 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. |
Since empty space in the computer’s memory is likely to be filled with zeros, any runaway program will eventually encounter a zero and attempt to execute this instruction, immediately stopping its execution. |