Each assembly language instruction must be translated into its corresponding machine code, including the locations of any data it manipulates. It is the bit pattern of the machine code that directs the activities of the control unit.
The goal here is to show you that a computer performs its operations based on bit patterns. That is, on-off switches that are connected in ways that were introduced in Chapters 5β8.
As you read through this material, keep in mind that even though this material is quite tedious, the operations are very simple. Fortunately, instruction execution is very fast, so lots of meaningful work can be done by the computer.
The four bits in the Rm field specify the number of the source register, and the four bits in the Rd field specify the destination register. The 32 bits in the source register are copied (moved) to the destination register. The instruction is conditionally executed, depending on the bit pattern in the cond field as given in Table 9.2.1. If S = 1 the instruction sets the condition flags according to the value being moved. If S = 0 the condition flags are not affected.
The four bits in the Rd field speciy the destination register. The 12 bits in the imm12 field are used as explained in Section 11.3.3 to produce a 32-bit value, which is stored in the destination register. The instruction is conditionally executed, depending on the bit pattern in the cond field as given in Table 9.2.1. If S = 1 the instruction sets the condition flags according to the value being moved. If S = 0 the condition flags are not affected.
The eight data bits are zero-extended to 32 bits, and the data is rotated to the right by twice the number of bits specified in the four-bit rot field. Rotation to the right consists of shifting all the bits one position to the right. The lowest-order bit is βrotatedβ around to the highest-order position.
Our next example will be the ldr instruction, which will illustrate pc-relative addressing. The bit pattern that makes up the machine code is shown in Figure 11.3.4.
A 32-bit value is copied from memory into the register specified by the four bits in the Rt field. The four bits in the Rn specify the base register, which contains the address of a reference memory location. The four bits in the Rm field specify the register that hold an offset value from the base address. This offset value can be shifted by the amount contained in the imm5 field. The type of shiftβlogical shift left; logical shift right; arithmetic shift right; rotate rightβ is coded in the two bits in the ty field.
The instruction is conditionally executed, depending on the bit pattern in the cond field as given in Table 9.2.1. If S = 1 the instruction sets the condition flags according to the value being moved. If S = 0 the condition flags are not affected.
Common values for Rn are (r11 or fp) for values in the stack frame, or (pc) for values in the .text segment. Addressing values in the .text segment is called pc-relative addressing.