ARM immediate number explains the difference between LDR and MOV.

Publisher:WhisperingWishLatest update time:2016-05-11 Source: eefocusKeywords:ARM Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
Mov is to assign an immediate value to a register, but there is a requirement for the range of the immediate value. It can only be a number that can be obtained by shifting 8 consecutive valid bits an even number of times. If the immediate value exceeds this range, there is no way to assign a value to the register using a MOV instruction.

In addition to normal reading, LDR also has the function of assigning immediate values ​​to registers.

You just need to write LDR R0, = 0xabcdef

It has no immediate range limit because it is a pseudo instruction. If the immediate value is within the requirements of MOV, it can be implemented in one assembly. If it is not within the range of MOV, it can be implemented in other ways, such as turning it into two instructions, or reading a 32-bit number from the PC offset address to a register.

MOV is to transfer the value of a register or shift register or immediate value to another register. It
is essentially a transfer from register to register. Why is there an immediate value? In fact, there are also limited immediate values. Not all immediate values ​​can be transferred.
This immediate value must conform to the value of an 8-bit number that is circularly shifted right by an even
number of bits. The reason is that MOV itself is a 32-bit instruction. In addition to the instruction code itself, it is impossible to carry a number that can represent 32 bits, so 12 bits are used to represent the immediate value, of which 4 bits represent the number of bits to be shifted (circularly shifted right, and the value is x2), and 8 bits are used to represent a base number to be shifted.

Another point about ldr is that it is not accurate to say that ldr can load a 32-bit immediate value, because it is not actually this statement that loads a 32-bit immediate value. For example,
ldr r1, =0x12345678.
In fact, the real assembly code is to pass the value of a certain address to r1, which means that an address is needed to store the immediate value 0x12345678. It can actually be regarded as a pseudo instruction.
And if this immediate value can be expressed in the form of a mov instruction, it will be replaced by mov by the compiler.
For example:
ldr r1, =0x10
will become
mov r1, #0x10

ARM is a RISC structure. The movement of data from memory to CPU can only be completed through L/S instructions, that is, ldr/str instructions. If you want to read data from somewhere in memory to a register, you can only use ldr. For example:

ldr r0, 0x12345678

That is to store the value at the address 0x12345678 in r0.

But mov can't do this job. It can only move data between registers or move immediate data into registers. This is the biggest difference from CISC architecture chips like x86. There is no ldr instruction in x86, because the mov instruction of x86 can move data from memory to register.

There is also another one, the ldr pseudo-instruction. Although the ldr pseudo-instruction is very similar to the ARM ldr instruction, its function is slightly different. The ldr pseudo-instruction can add = before the immediate value to indicate that an address is written to a register, for example:

ldr r0, =0x12345678

In this way, the address 0x12345678 is written to r0. Therefore, the ldr pseudo-instruction is similar to mov. However, the mov instruction limits the length of the immediate value to 8 bits, that is, it cannot exceed 512. The ldr pseudo-instruction does not have this limitation. If the ldr pseudo-instruction is used and the immediate value following it does not exceed 8 bits, then the ldr pseudo-instruction will be converted to the mov instruction during actual assembly.

The ldr pseudo-instruction and the ldr instruction are not the same thing.

Keywords:ARM Reference address:ARM immediate number explains the difference between LDR and MOV.

Previous article:What is the difference between mov and ldr in arm instructions
Next article:The difference between ARM instruction set and Thumb instruction set

Recommended ReadingLatest update time:2024-11-16 15:01

Linux ARM (IMX6U) bare metal assembly LED driver experiment-burn bin file to SD card to run
Code burning Although I.MX6U has 96K ROM inside, this 96K ROM is used by NXP itself and is not open to users. So it is equivalent to saying that I.MX6U has no internal flash, but our code must be stored somewhere. For this reason, I.MX6U supports booting from external storage media such as NOR Flash, NAND Flash, SD/EM
[Microcontroller]
Linux ARM (IMX6U) bare metal assembly LED driver experiment-burn bin file to SD card to run
Solution to ARM debugging DAbt_Handler problem
Problem: My ARM application does not work. When I run it in a software emulator or JTAG debugger, I notice that the program counter (PC/R15) jumps to the DAbt_Handler label. Q: What does this mean? How can I find out where my program crashed? A: This is the default Data Abort exception handler. Your application tried
[Microcontroller]
ARM9 Registers
CPSR register (program status):    T flag: 1: THUMB state (instructions are 16-bit half-aligned) 0: ARM state (instructions are 32-bit aligned)        I, F: interrupt mask bits, setting them to 1 can mask IRQ and FIQ interrupts accordingly  M4-M0: Processor operating mode bits, can only work according to the followin
[Microcontroller]
ARM9 Registers
Design of embedded system based on PXA270
0 Introduction With the development of embedded systems, product functions and power consumption have become increasingly important aspects to be considered in system design. Products that only have rich functions but high power consumption cannot meet people's needs. The PXA270 processor based on the Intel XSc
[Microcontroller]
Design of embedded system based on PXA270
Design and implementation of high-speed and high-precision data acquisition system
Abstract: A data acquisition system based on FPGA and ARM chips is designed. FPGA is responsible for controlling the A/D converter to ensure sampling accuracy and processing speed. ARM is responsible for logic control and the realization of interaction with the host computer, and the collected data is uploaded to the
[Microcontroller]
Design and implementation of high-speed and high-precision data acquisition system
How many CPU architectures are there? What are the differences between X86 and ARM? You will understand after reading this
What is the most important electronic component of a server, a computer, or a mobile phone? That's right, it's the CPU processor. It is mainly responsible for data calculation and control functions, and is the core part. But do you know how many types of CPU architectures there are? What is the difference between the
[Microcontroller]
How many CPU architectures are there? What are the differences between X86 and ARM? You will understand after reading this
GNU-ARM Assembly
Part 1 ARM assembly syntax under Linux Although it is convenient to write programs in C or C++ under Linux, the assembly source program is used for the most basic initialization of the system, such as initializing the stack pointer, setting up the page table, operating the ARM coprocessor, etc. After the initializatio
[Microcontroller]
Arm's IPO has been 10 times oversubscribed or may close early
According to people familiar with the matter, Arm Holdings Ltd. The initial public offering (IPO) has been 10 times oversubscribed, and banks plan to stop accepting subscriptions by Tuesday afternoon. SoftBank Group Corp.'s Arm will end subscriptions a day early on Tuesday, but still plans to price on Wednesday, said
[Semiconductor design/manufacturing]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号