Now that we are familiar with the Watson Virtual Machine language instruction set, we can examine the process of translating programs from the assembly level to the machine level.
There are eighteen commands in the Watson assembly language. There are sixteen commands in the Watson Virtual Machine language. Referring back for an overview of the assembly language and for an overview of the machine language, we can see that with the exception of the .WORD and .BLOCK commands, every assembly language instruction maps to exactly one machine language instruction. Thus the process of translation between these two levels is straightforward and can be automated.
The programs that automatically translate assembly language programs to machine language are called “assemblers”. Essentially, assemblers construct or “assemble” each of the machine language instructions of a program from the corresponding instruction in the assembly language version of the program. illustrates the relationship between assembly language and machine language with an example program first shown in .
Machine and assembly language versions of the same program
The translation process from assembly language to machine language is described below for the Watson Virtual Machine. While the process is simplified somewhat from what goes on in “real” systems, it should be sufficient to give you a feel for what happens when an assembly language program is translated to machine code and loaded into memory for execution.
Beginning at some starting address (address zero in the Watson VM), reserve memory as specified by the .BLOCK and .WORD commands. Perform the initializations required by the .WORD commands. Also note labels associated with each word, block, and command as they are encountered. For example, TOTAL, ABC, and XYZ are labels in the program of . After processing each of the .WORD and .BLOCK commands the “data segment” of your machine language program will be complete.
The executable instructions of a machine language program will immediately follow its data segment. For each assembly language instruction, use the table of to produce a machine language equivalent. Instruction names at the assembly level are mapped to op-codes at the machine level. References to registers at the assembly level are mapped to 4-bit unsigned register numbers. Labels at the assembly level are replaced with the address associated with that label at the machine level. And so forth.
At the conclusion of this process, the machine language equivalent of the assembly language program will be held in the main memory of the Watson Virtual Machine. In order to begin program execution, the program counter is loaded with the address of the first executable machine language instruction – the first instruction following the data segment.