Instruction basic Format:
<opcode>{<cond>}{s} <rd>,<rn>{,<operand2>}
1, the items within the <> are required, {} Items are optional, cond use the default condition if no instruction is used Al (Unconditional execution).
2, opcode: instruction mnemonic, such as LDR,STR, etc.;
3, cond: implementation conditions, such as eq,ne, etc.;
4, S: Whether the value of the CPSR register is affected;
5, Rd: Target register;
6, Rn: The register of the first operation number;
7, Operand2: the second operand; In an arm directive, the flexibility to use the second operand increases the efficiency of the Code, and the second operand is in the form of:
√ #immed_8r-constant expression;
√rm--Register mode;
√rm,shift--register shift mode;
The instruction encoding format is as follows:
31-28 |
27-25 |
24-21 |
20 |
19-16 |
15-12 |
11-0 (12-bit) |
Cond |
001 |
OpCode |
S |
Rn |
Rd |
Shifter_operand |
#immed_8r:
The constant must correspond to a 8-bit bitmap (that is, the spacing between the first two "1" bit is 6bits and the constant passes through the loop to the left of all bit=1 bits must be concentrated at a low 8bits). such as 0X1FE, 511, 0xFFFF, 0x1010, 0xf0000010 are illegal constants, 0X3FC, 0, 0xf0000000, 200, 0xf0000001 are legal constants.
The clever implementation of this transformation is the integration of an immediate number (constant) of 32bits in the arm instruction code of 32bits. The instruction code for an immediately addressable data processing instruction is: xxxx001a aaasnnnn ddddrrrr bbbbbbbb, then its second operand op2= #b, ROR #2r, and the conversion from OP2 to script is done by the compiler.
The constant expression for the Operand2 has the following rule: "The constant must correspond to a 8-bit bitmap, that is, Changshu is obtained by a 8-bit Changshu loop right-shift even number." "The meaning of this remark is that when a 12-bit second operand is used to represent a 32-bit immediate number, it is implemented by shifting the 8-bit number, where the lower eight bits of the second operand of 12 bits hold the" base "number of the shift (the range is 0 to 255), and the high four bits hold the number of bits in the loop right shift. Because of the bit four-bit binary number, the value range bit is 0 to 15, and the corresponding shift number is 0 to 30 bits, that is, if the "shift" number is 0, then the "basic" number is unchanged, if "shift" digit 1, then the "basic" number in the 32-bit digital space loop right 2 bits, if "shift" digit 5, it means The "basic" number loops right 10 bits in 32-bit digital space, and if "shift" digit 10, it means that the "basic" number in 32-bit digital space loop right 20 bits, and so on. For example:
and R1,R2, #0xff
When the processor processes the second operand of the instruction 0xFF, because 0xFF is a 8-bit binary number, the processor puts it directly into the 8-bit "base" number, while the 4-bit "shift" number is 0.
and R1,R2, #0x104
When the processor handles the second operand of this instruction 0x104, because at this point the 0x104 has exceeded the 8-bit binary number, so the processor is going to "transform" it, we first convert the 0x104 to binary 0000 0000 0000 0000 0000 0001 0000 0100, As we can see, this number is 0000 0000 0000 0000 0000 0000 0100 0001 is obtained by looping right shift 30, so the result of the transformation is 8-bit "basic" in the number of 0100 0001, while the "shift" number is 15.
and R1,R2, #0xff000000
When the processor handles the second operand of this instruction 0xff000000, the processor also "transforms" it, we first convert the 0xff000000 to binary 1111 1111 0000 0000 0000 0000, 0000 0000, we can see that this number is 0000 0000 0000 0000 0000 0000 1111 1111 is obtained by looping to the right by 8 bits, so the result of the transformation is 8-bit "basic" in the number of 1111 1111, while the "shift" number is 4.
I think, through the above three examples, you should understand the principle of 8-bit bitmap. However, some numbers do not conform to the principle of 8-bit bitmap, such a number in the program compile, the system will prompt an error, the following is a few examples of violations of the 8-bit bitmap: For example, 0x101, converted to binary after the bit 0000 0000 0000 0000 0000 0001 0000 0001, like this number, No matter how many to the right, you can not put two 1 at the same time in the lower 8 bits, and therefore does not conform to 8-bit bitmap, and then for example, 0x102, converted to binary after the bit 0000 0000 0000 0000 0000 0001 0000 0010, if two 1 are placed in the low 8 bit, That is, after converting to binary 0000 0000 0000 0000 0000 0000 1000 0001, this binary number needs to be shifted to the right 31 bits, which does not conform to the conditions of the loop right-shift even digits, so 0x012 also does not conform to the 8-bit bitmap; one more 0xff1, Converted to binary will have 9 1, it is not possible to put it in 8 bits, so of course it does not fit.
The comparison of positive and negative examples can be summarized as follows: first, to determine whether a number conforms to the principle of 8-bit bitmap, first of all to see if the number is converted into binary after the number of 1 is not more than 8, if not more than 8, then see if the N 1 (n<=8) can be put in 8 bits, if can be put Then see whether these eight bits can loop right-shift even digits to get the first judgment of the value, if possible, then this value is consistent with the 8-bit bitmap principle, otherwise, does not conform. Second, it is not possible to use 12-bit encoding to represent an arbitrary 32-digit number, only by looping right eight-bit binary digits to get a portion of the 32-digit number, the remaining 32-digit number that cannot be represented, only by other means, such as 0xffffff00, Can be reversed by 0x000000ff, so in future programming, it is important to note whether the second operand that is used conforms to the 8-bit bitmap.
Rm:
In the Register mode, the second operand is the number of the Register;
Rm,shift:
In the register shift operation mode, the shift result of the register is used as the operand, but the RM value remains the same, the shift method has the following:
where n values are generally between 1--31.
8. The ARM instruction set:
9. Instruction Condition Code: