LDR and LDR commands in ARM assembly
ARM is a hierarchical structure. Data movement from memory to CPU can only be completed through the L/S command, that is, ldr/s.TrCommand. For example, if you want to read data from somewhere in the memory to a register, you can only use ldr, for example:
ldr r0, 0x12345678
Store the value in 0x12345678 to r0. However, mov cannot implement this function. mov can only move data between registers, or move the immediate number to the Register, which is similar to CISC such as x86.
ArchitectureThe biggest difference between chips. There is no ldr command in x86, because the mov command of x86 can move data from memory to registers.
The other is the ldr command. Although the ldr command is similar to the ARM's ldr command, it does not play the same role. The ldr pseudo command can add = before the immediate number to write a value (generally an address) to a register, for example:
ldr r0, =0x12345678
In this case, the 0x12345678 value is written to r0. Therefore, ldr pseudo commands are similar to mov commands. However, the mov command limits the length of the immediate number to 8 bits, that is, it cannot exceed 512. The ldr Directive does not have this restriction. If the number of immediate digits following the ldr command does not exceed 8 bits, the ldr command is converted to mov command during actual compilation.
In fact, it is not accurate to say that the ldr command can load a 32bit immediate number, because this statement does not actually load a 32bit immediate number, the actual assembly code is to pass the value of an address to r1, that is, an address is required to store the immediate number 0x12345678. Moreover, if the immediate number can be expressed in the form of mov commands, it will be replaced by mov by the compiler, for example:
ldr r1,=0x10
Will become
mov r1,#0x10
Summary: The ldr pseudo command is used to load a 32-bit immediate number or an address value to the specified register. When compiling the source program, the ldr pseudo command is replaced by an appropriate one by the compiler. If the loaded constant does not exceed mov or
MvIn the range of n, the mov or mvn command is used to replace the ldr pseudo command. Otherwise, the assembler puts the constant into the text pool and reads the constant from the text pool using a program's relatively offset ldr command.
The ldr Directive and the ldr directive are not the same thing. Http://www.linuxso.com/linuxrumen/16306.html
- Summary of adr adrl ldr mov
- System classification: Embedded System Custom classification: arm
Tags: arm
This is a small range of address read pseudo command, which reads PC-based relative offset address value to the target register.
Format: ADR register, exper.
When compiling the source program, the assembler first calculates the distance from the current PC value (current command location) to exper, and then replaces this pseudo command with an ADD or SUB command, for example: ADD register, PC, # offset_to_exper.
Note that the number exper must be in the same code segment as the instruction.
Example: adr r0, _ start: assigns the specified address to r0.
.........
_ Start:
B _ start
The r0 value is the Distance Difference Between the label _ start and the command + PC value (current command position)
ADRL:
This is a medium range of address read pseudoinstructions, it will be based on the PC relative offset of the address value to the target register.
Format: ADRL register, exper.
When compiling the source program, the assembler replaces this pseudo command with two appropriate commands.
For example:
ADD register, PC, offset1
ADD register, register, offset2
Compared with ADR, it can read a wider range of addresses.
Note that the number exper must be in the same code segment as the instruction.
The next step is LDR. The first thing we want to talk about is that there are two guys called LDR.
One is the LDR pseudocommand, and the other is the LDR command, with the same name but not one thing.
The distinguishing method is to look at the second parameter. If there is an equal sign, it is a pseudo command.
LDR command:
For example, ldr r0, 0x12345678 stores the value in 0x12345678 to r0. But mov cannot do this job. mov can only move data between registers, or move the number of immediately to registers.
LDR pseudocommand:
Example 1 (immediate number): ldr r0, = 0x12345678
In this way, the address 0x12345678 is written to r0. Therefore, ldr pseudo commands are similar to mov commands. However, the mov command limits the length of the immediate number to 8 bits, that is, it cannot exceed 512. The ldr Directive does not have this restriction. If the number of immediate digits following the ldr command does not exceed 8 bits, the ldr command is converted to mov command during actual compilation.
Example 2 (Label): ldr r0, = _ start: Assign the value of the specified label to r0
Here we get the absolute address of the label _ start, which is determined at the link. It occupies 2 32bit space, one is the instruction, and the other is the absolute address for storing _ start in the text pool.
Here we will compare the adr r0, _ start, and ldr r0, = _ start
They have the same purpose. To give the tag address to r0, the difference is relative address and absolute address. The goal is the same, but the results are not necessarily the same. Whether the results are the same depends on whether the PC value is the same as the link address. PC value, and link address,