LDR Pseudo-directives and LDR directives in arm assembly

Source: Internet
Author: User

ARM Assembly Language is RISC structure, the movement of data from memory to CPU can only be done by l/s instruction, that is, ldr/s tr instruction.

For example, to read data from somewhere in memory to a register, you can only use LDR such as:

 

Ldr R0, 0x12345678

is to store the value of the 0x12345678 address in the r0 . and mov can not achieve this function,mov can only move data between registers, or to move the number of immediate to register, this and x86 this CISC architecture chip distinguish the biggest place. There is no such instruction in x86 because x86 's mov instruction can move data from memory to registers.

 

another is the LDR pseudo-directive, although the Ldr pseudo-directive and ARM 's ldr directive are very similar, but the function is not quite the same. Ldr Pseudo-directives can be preceded by an immediate number of =to indicate that a value (usually an address) is written to a register, for example:

 

Ldr R0, =0x12345678

In this way, we write the value of 0x12345678 toR0In the. SoLdrPseudo-directives andmovis more similar. Justmovdirective limits the length of the immediate number to8A bit, that is, cannot exceed +。 andLdrPseudo-directives do not have this limitation. If you useLdrPseudo-instruction, the immediate number followed is no more than8Bit, then in the actual assembly of the time thatLdrPseudo-directives are converted tomovdirective. In factLdrInstruction can load a32bitThe argument for the immediate number is not exact, because it is not actually a statement that loads a32bitImmediately, the real assembly code is to pass the value of an address to theR1, which means you need an address to store0x12345678This is the immediate number. And if the immediate number can be usedmovIn the form of an instruction, it is actually used by the compiler.movTo replace, for example:

LDR r1,=0x10

will become

mov r1, #0x10

< Span style= "font-family: the song Body;" >          review: LDR pseudo-directives are used to load 32 The immediate number of the bit or an address value to the specified register. When compiling the source program, ldr pseudo-instruction is replaced by the compiler with an appropriate instruction. If the constant loaded does not exceed mov or  MV n Range, Use mov or mvn directive instead of the ldr pseudo-directives, otherwise the assembler puts constants into the text pool and uses a ldr instruction to read the constants from the text pool.          ldr pseudo-directives and LDR directive is not a common thing.  http://www.linuxso.com/linuxrumen/16306.html

ADR This is a small-scale address read pseudo-instruction that reads the address value based on the relative offset of the PC into the target register.

 

format used: ADR register,exper.

 

when compiling the source program, the assembler first calculates the current PC value (current instruction position) to exper , and then replaces the pseudo-directive with an ADD or SUB instruction. For example : ADD register,pc, #offset_to_exper.

 

Note that the designator Exper must be in the same code segment as the instruction.

 

Example: ADR R0, _start: Assigning the specified address to r0

 

.........

 

_start:

 

b _start

 

the value of R0 is the label _start distance difference from this instruction + PC value (current instruction position)

 

ADRL:

 

This is a medium-range address read pseudo-instruction that reads the address value of the relative offset of the PC into the target register.

 

format used: ADRL register,exper.

 

when compiling the source program, the assembler replaces the pseudo-directive with two appropriate instructions.

 

For example:

 

ADD Register,pc,offset1

 

ADD Register,register,offset2

 

it can read a larger range of addresses than ADR.

 

Note that the designator Exper must be in the same code segment as the instruction.

 

Next is LDR, the first thing to say is that there are two guys, all of them called LDR.

 

one is the LDR pseudo-directive, the LDR directive, the same name but not a thing.

 

the way to differentiate is to look at the second parameter, if there is an equal sign, is a pseudo-directive.

 

LDR directives:

 

Example: Ldr r0, 0x12345678 is the value of 0x12345678 in this address is stored in the r0 . and mov can not do this job,mov can only move data between registers, or to move the number of immediate to register.

 

LDR Pseudo-directives:

 

Example 1 (immediate number): ldr r0, =0x12345678

 

in this way, the 0x12345678 address is written to the R0 . Therefore,Ldr Pseudo-instructions and mov are more similar. Only the mov instruction limits the immediate number of the length to 8 bits, that is, cannot exceed the limit. The Ldr pseudo-directive does not have this limitation. If the Ldr pseudo-directive is used and the immediate number followed is not more than 8 bits, then the Ldr pseudo-directive is converted to the mov instruction at the time of the actual assembly.

 

Example 2 (label): Ldr r0, =_start : Assigns the value of the specified label to r0

 

here is the absolute address of the label _start, this absolute address (running address) is determined at the time of the link. It takes 2 32bit of space, one is the instruction and the other is the absolute address of the _start in the text pool.

 

compare here, ADR R0, _start, and Ldr r0, =_start

 

Their purpose is the same, want to put the address of the label to R0, the difference is a relative address, one is an absolute address. purposes, but the results are not necessarily the same. Whether the result is the same, depends on the value of the PC , and the link address is the same.

 

 

Article Source: Chinaunix Blog

LDR Pseudo-directives and LDR directives in arm assembly

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.