Tips
The order of the notes may be disordered, according to your own thoughts and understanding, and will be sorted out later when there is time.
About ARM Thumb2 instruction set
The number of bytes in the instruction set
Most ARM Thumb2 instructions are 2 Bytes or half words, while some instructions nested with other instructions, such as the most common # instruction, require 4 Bytes or one word to store.
Special note : In general, 16 bits are used to represent, and a "bit" in hexadecimal is equivalent to 4 "bits" in binary, so for byte, one byte corresponds to binary The next 8 bits correspond to the next 2 bits in hexadecimal, and the half word size is 2byte, so half word needs to be represented by 4 hexadecimal "bits", and a word needs to be represented by 8 hexadecimal "bits.
Examples:
Assembly language | Address representation |
---|---|
MOV r0, #10 | 08000190: F0 4F 00 0A |
LDR r2, [r1] | 08000194: 68 11 |
ADD r0, r0, r2 | 08000196: 44 10 |
As can be seen from the above example, every two hexadecimal "bit" is a byte, so put together, every four bits is two bytes, that is, a half word, two half words form a word.
About the offset of the instruction
The offset of the instruction is obtained by the difference operation of the two instruction addresses, which is positive and negative, especially pay attention to the hexadecimal calculation, you can first subtract the small address from the large address and then determine the positive and negative.
Special note: The offset does not need to maintain the same 8-bit address as the command
Example:
0x08000190 + 0x1A-> 0x0800020A
0x0800020A-0x1A-> 0x08000190
Assembly language (C)
Common sentences
MOV can be used to assign
MOVS with carry
ADD addition
ADDS with carry
SUB subtraction
SUBS with carry
MUL multiplication
UDIV division
LDR load
STR storage
Control flow
if statement
void func(int a){
if(a==0){
a=1;
}
}
compilation
void func(int a){
CMP r0,#0
BEQ CON1
COND1
MOVS r0,#1
BX lr
}
for statement
void func(int a)
{
for(int i=0;i<5;i++){
a--;
}
}
compilation
void func(int a)
{
MOVS r1,#0
LOOP
CMP r1, #5
BLS ENDLOOP
ADDS r1,r1,#1
SUBS r0,r0,#1
B LOOP
ENDLOOP
BX lr
}
while statement
void func(int a)
{
while(a>0){
a--;
}
}
compilation
void func(int a)
{
LOOP
CMP r0, #0
BLT ENDLOOP
SUBS r0,r0,#1
B LOOP
ENDLOOP
BX lr
}
To be continued. . .