ARM microprocessor instruction set Overview (5) -- zookeeper LDR and ADR Analysis

Source: Internet
Author: User
Tags sub command

The definition of ADR is: a small range of addresses read pseudoinstructions, the ADR command reads the address value based on the relative offset of the PC to the register, when the source program is compiled, the ADR directive is replaced by an appropriate directive by the compiler. Generally, the compiler uses an add or sub command to implement the function of this ADR pseudocommand. If it cannot be implemented using one command, an error has just occurred.

In the above definition, there are two key information: (1) read the address value based on the relative offset of the PC to the register; (2) Replace it with a proper instruction by the compiler. The ADR command can only read the address value into the register, rather than the other immediate number, and can only use one command.

If the ADR R1 and resethandel statements are used in the assembler, where resethandel is a label in the assembler, this pseudoinstruction reads the instruction address of the resethandel label to the R0 register. When the assembler compiles this pseudo command, it translates the code into a machine code: 0xe28f100c and converts it into a binary code of 1110, 0010, 1000, 1111, 0001, 0000, 0000, 1100, and analyzes the machine code below:

According to the above analysis, we can see that the compiler compiles the ADR pseudo command into an add R1, PC, and immediate command during compilation, where immediate is an immediate number, the value is the difference between the resethandel statement and this pseudocommand, which is automatically calculated by the compiler. Due to the number of immediate addressing constraints, this immediate has certain constraints, so what is mentioned in the definition cannot be implemented using a single instruction.

 

 

LDR is defined as a large-scale address read pseudocommand. The LDR pseudo command is used to load the immediate Number of 32 or an address value to the specified register. When compiling the source program, the LDR pseudo command is replaced by an appropriate command by the compiler. If the loaded constant does not exceed the mov or MVN range, the mov or MVN command is just used to replace the LDR pseudo command. Otherwise, the assembler puts the constant into the word pool, and read constants from the text pool using a program's relatively offset LDR command.

Compared with the LDR of the arm command, the LDR parameter of the pseudo command has the "=" number.

In the above definition, there are three key pieces of information: (1) loading the immediate number or an address value of 32 to the specified register; (2) replacing it with an appropriate instruction by the compiler; (3) Replace the mov or MVN command first.

If the mov command is used, the immediate number addressing method is used, but the immediate number addressing has a range white constraint, so not all constants can use the immediate number addressing white mode. When the stand-by-number addressing mode is not available, the constant is put into the text pool, and the content of the text pool is read to the register using the LDR command of a program relative to the PC addressing. The number of immediate actions is the same as the address value.

If there is a pseudo command: LDR r0, = 0x123456. Then the compiler will compile the pseudo-command into a machine code: 1110 0101 1001 1111 0000 0000 0001 0100, and analyze the machine code below:

According to the analysis above, the pseudocommand LDR r0, = 0x123456 is actually compiled into LDR r0, [PC, immediate]. The number 0x123456 is stored in a text pool. Immediate is different from the address of the command LDR r0, [PC, immediate. Therefore, the command LDR r0, [PC, immediate] can read the immediate number 0x123456 to R0.

Original article: http://tanglei9098.blog.163.com/blog/static/502021152010312104430781/

LDR is a command in arm and also a pseudo command.

When LDR, = IMD // R is used as the register, IMD is the immediate number

LDR is a pseudo command. The compiler determines whether to use the LDR command or mov or MVN command based on the size of the number of immediate values.

When IMD can be operated by mov or MVN, it is translated into an mov or MVN command. When IMD is greater than mov or MVN, the compiler will store IMD in a memory unit, and then use a LDR command to load the value of this memory unit into the register.

Ldr r, label, and LDR, = label:

LDR, = label will load the value represented by label into the Register, while LDR and label will use label as the address and load the value from the address pointed by label to the Register.

For example, if the label value is 0x8000, LDR, = label will load 0x8000 to the Register, while LDR and label will load the value at memory 0x8000 to the Register.

ADR and adrl pseudocommands:

The ADR and adrl commands are used to load an address into a register.

ADR reads pseudocommands from a small range of addresses. The ADR command reads the address value of the PC relative offset to the Register. During compilation of the source program, the ADR pseudo command is replaced by the compiler in a suitable command. Generally, the compiler uses an add or sub command to implement the ADR pseudo command function, if a command cannot be used for implementation, an error is generated. The address range that can be loaded. The value range is-1020 ~ when the byte is aligned ~ 1020. When non-Word Alignment occurs ~ In the range of 255.

Adrl is an address read instruction in a medium range. It will be translated into two commands by the compiler. If two commands cannot be used, an error is generated.

The address range that can be loaded by adrl is-64 kB ~ when non-byte alignment occurs ~ 64 KB to 64 KB;-kb to-KB ~ Between kb.

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.