Analyzing instructions
In this section, we will look at the way in which we take a text string representing an assembly language instruction and process it to create binary code that can be executed by the simulator.
Interestingly, the assembler can be more complicated than the actual simulator. Indeed, we devote relatively little space to the simulator itself in this chapter. We don’t actually need an assembler, because it’s easy to hand-translate assembly-level operations into binary code; it’s just a matter of filling in the fields of the 32-bit instruction format. For example, load register R7 with the literal value 42 can be written as LDRL
R7
,42
. This has a 7-bit opcode, 01
01010
, the destination register is r7
(code 111
), the two source registers are not used, and their fields can both be set to 000
. The literal is 42
, or 0000000000101010
as a 16-bit binary value. The binary-encoded instruction is as follows:
0001010111000000
0000000000101010
It...