Difference between LDR commands and LDR pseudo commands

Source: Internet
Author: User

In the arm instruction set, LDR is usually used as the loading command, but it can also be used as a pseudo command.
Beginners generally do not notice their differences. In fact, these two commands are very common during embedded development! We should understand their differences.

The form of the LDR pseudo command is "ldr rn, = expr ". It is installed in a 32bit constant and an address to the Register.
The following is an example to describe its usage.

Count equ 0x56000054
LDR R1, = count
MoV r0, #0
STR r0, [R1]

Count is a defined variable with the address 0x56000054.

LDR R1, = count is the address of the variable count, that is, 0x5621354 is put into R1.
MoV r0, #0 is to put the immediate number 0 into R0.

STR r0, [R1] is a typical storage command that places values in R0 to the storage unit where the values in R1 are the addresses.
Actually, 0 is placed in the storage unit where the address is 0x5621354.
The three commands are used to assign values to the variable count.

Another example
LDR R1, = count; this pseudo command assigns the Count address to r1
LDR r0, [R1]; assigns the value of Count to R0
Arm is a hierarchical structure. data can only be moved from memory to CPU using the LDR/STR command.
For example, 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.

But mov cannot do this job. mov can only move data between registers, or move the immediate number to the Register, which is the most different from the chip of the CISC architecture such as x86.
There is no LDR command in x86, because the mov command of X86 can move data from memory to registers.
MoV is transmitted from a register or a shift register or an immediate number value to another register.
In essence, it is the transfer of registers to registers. Why is there an immediate number? In fact, there are limits on the immediate number. Not all immediate numbers can be passed.
The immediate number must conform to the value of an 8-digit loop with an even number shifted to the right.
The reason is that mov itself is a 32bit command. Apart from the instruction code itself, it cannot contain a number that can represent 32bit. Therefore, it uses 12bit to represent the immediate number, here, 4-bit indicates the number of digits to be shifted (cyclic right shift, and the value is x2), and 8-bit indicates a base number to be shifted.

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 an address to a register. For example:
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.

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.