The ARM microprocessor supports loading/storing commands for transferring data between registers and memory. Loading commands are used to transfer data from memory to registers, and storing commands perform the opposite operation. Common commands for loading storage are as follows:
-LDR data loading command
-Ldrb byte data loading command
-Ldrh half-word data loading command
-Str data storage command
-Strb byte data storage command
-Strh half-character data storage command
1. LDR commands
LDR command format:
LDR {condition} destination register, <memory address>
LDRCommand is used to extract32To the destination register. This command is usually used to read from memory32And then process the data. When the program counterPCAs the destination register, the word data read by the instruction from the memory is treated as the destination address, so as to redirect the program flow. This command is commonly used in programming and has various addressing methods. Please master it carefully.
Command example:
LDR r0, [R1]; read the word data with the memory address R1 into the register R0.
LDR r0, [R1, R2]; read the word data with the memory address R1 + R2 into the register R0.
LDR r0, [R1, #8]; read the word data with the memory address R1 + 8 into the register R0.
LDR r0, [R1, R2]! Read the word data with the memory address R1 + R2 into the register r0, and write the new address R1 + R2.
LDR r0, [R1, #8]! Read the word data with the memory address R1 + 8 into the register r0, and write the new address R1 + 8 into R1.
LDR r0, [R1], R2; read the word data with the memory address R1 into the register r0, and write the new address R1 + R2.
LDR r0, [R1, R2, LSL #2]! Read the word data with the memory address R1 + R2 × 4 into the registers r0, and write the new address R1 + R2 × 4 into R1.
LDR r0, [R1], R2, LSL #2; read the word data with the memory address R1 into the register r0, and write the new address R1 + R2 × 4 to R1.
2. ldrb commands
The ldrb command format is:
LDR {condition} B destination register, <memory address>
LDRBCommand is used to extract8To the destination register.24Bit is cleared. This command is usually used to read from memory8To the General Register, and then process the data. When the program counterPCAs the destination register, the word data read by the instruction from the memory is treated as the destination address, so as to redirect the program flow.
Command example:
Ldrb r0, [R1]; read the byte data of the memory address R1 into the register r0, and clear the 24-bit high of R0.
Ldrb r0, [R1, #8]; read the byte data with the memory address R1 + 8 into the register r0, and clear the high 24 bits of R0.
3. ldrh commands
The ldrh command format is:
LDR {condition} H destination register, <memory address>
LDRHCommand is used to extract16Transmits the half-word data of bits to the destination register16Bit is cleared. This command is usually used to read from memory16And then process the data. When the program counterPCAs the destination register, the word data read by the instruction from the memory is treated as the destination address, so as to redirect the program flow.
Command example:
Ldrh r0, [R1]; reads the half-character data with the memory address R1 into the R0 register, and clears the high 16-bit value of R0.
Ldrh r0, [R1, #8]; read the half-character data with the memory address R1 + 8 into the register r0, and clear the high 16-bit R0.
Ldrh r0, [R1, R2]; read the half-character data with the memory address R1 + R2 into the register r0, and clear the high 16-bit R0.
4. Str command
STR command format:
STR {condition} source register, <memory address>
STRCommand is used to set32Bit of word data is transmitted to the memory. This command is commonly used in programming and has a variety of addressing methods. For instructions, seeLDR。
Command example:
STR r0, [R1], #8; write the word data in R0 to the memory with R1 as the address, and write the new address R1 + 8 to R1.
STR r0, [R1, #8]; write the word data in R0 to the memory with R1 + 8 as the address.
5. strb commands
The strb command format is:
STR {condition} B Source register, <memory address>
STRBCommand is used to set8Bytes of data are transmitted to the memory. The byte data is low in the source register.8Bit.
Command example:
Strb r0, [R1]; write the byte data in register R0 to the memory with R1 as the address.
Strb r0, [R1, #8]; write the byte data in register R0 to the memory with R1 + 8 as the address.
6. strh commands
The strh command format is:
STR {condition} H source register, <memory address>
STRHCommand is used to set16The half-word data is sent to the memory. The half-character data is the low value in the source register.16Bit.
Command example:
Strh r0, [R1]; write the half-word data in the R0 register to the memory with R1 as the address.
Strh r0, [R1, #8]; write the half-character data in register R0 to the memory with R1 + 8 as the address.