Differences between mov and LDR in arm

Source: Internet
Author: User

 

The arm is a hierarchical structure. The movement of data from memory to CPU can only be completed through the L/s command, that is, the LDR/STR command. For example, if you want to read data from somewhere in the memory to a register, you can only use LDR such as LDR R0 and 0x12345678 to store the value in the address 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. 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. Then, 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. The LDR Directive and the LDR directive are not the same thing.

LDR r0, = 0x56000010 @ R0 is set to be register gpbcon and is used to select pin function for port B
@ In, out special function and others
MoV RR1, #0x00004000
STR R1, [R0] @ pin gpb7 is set to be output port

The functions of the preceding three Assembly statements are to store the value 0x00004000 to a storage unit with the address 0x56000010.

The disassembly code is as follows:

0: e59f0044 LDR r0, [PC, #68]; 0x4c
4: e3a01901 mov R1, #16384; 0X4000
8: e5801000 STR R1, [R0]

......

4c: 56000010 undefined

LDR r0, = 0x56000010 is converted to the LDR command for execution.

Let's take a look.

LDR r0, = 0x56000000

MoV RR1, #0x00004000
STR R1, [R0]

The disassembly code is as follows:

0: e3a00456 mov r0, #1442840576; 0x56000000
4: e3a01901 mov R1, #16384; 0X4000
8: e5801000 STR R1, [R0]

Here LDR r0, = 0x56000000 is converted to mov r0, #1442840576

That is to say, the LDR pseudo command is based on the subsequent data values to decide the conversion to the LDR command or mov command execution.

 

Similarly, we assign a value to R0. Can LDR r0, = 0x56000010 be replaced by mov r0, #0x561_10,

There is a limit on the immediate number after the mov command. This immediate number must be obtained by an eight-bit binary number after an even number of shifts to the right to obtain valid data.

LDR r0, = 0x56000000 is converted to mov r0, #0x56000000, where the number of immediate 0x56000000 can be obtained by the right shift of 0x56 through loops, 0x5621310 cannot be obtained after an even number of eight-bit binary values are shifted to the right, so it cannot be converted to the mov command.

An example is as follows:

MoV r0, #0x101

MoV r0, #0xff1

The preceding two commands are incorrect because the immediate number is invalid.

In this case, using mov commands is troublesome, because some simple data is easier to see, and some data is not easy to see if it is legal data.

To solve this problem, we can use the LDR pseudo command to implement the conversion to the LDR command or mov command execution based on the subsequent number of immediate commands, if the value of the valid number of mov commands is not met, the value is converted to the mov command. If the value is not met, the value is converted to the LDR loading command.

Source: http://liudapeng890.blog.163.com/blog/static/4336440320109214259385/

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.