当前位置:网站首页>ARM assembly instruction ADR and LDR
ARM assembly instruction ADR and LDR
2022-08-11 06:34:00 【Emily_rong_2021】
Introduction
Both are pseudo-instructions: ADR is a small-range address read pseudo-instruction, and LDR is a large-range address read pseudo-instruction.The practical differences are: ADR is a pseudo-instruction that reads an address value based on a PC-relative offset or a register-relative address value, while LDR is used to load a 32-bit immediate value or an address into a specified register.
adr r0, _start gets the current execution position of _start, and the effective address is determined by pc+offset
ldr r0, =_start gets the absolute address, which is determined when linking;
------------------------------------------------------------------------
/* Relocate Boot code to RAM memory, move Boot code from FLASH to RAM */
relocate: /* relocate U-Boot to RAM */
adr r0, _start /* r0 <- current position of code */
/****************************************************************************
* Move the relative address of _start to r0, the relative addressing takes the current value of the program counter PC as the base address,
* The address label in the instruction is used as the offset, and the twoAfter the addition, the effective address of the operand is obtained.
* It is independent of position, mainly depends on where Boot is running, that is, where the PC pointer is (assuming the _start offset is 0),
* For example, this code is at 0x02000000 (FLASH start address) to run, that is, PC=0x02000000 at this time, then adr r0, _start gets r0 = 0x02000000;
* If it runs at address 0x81008000 (Boot loads the address in RAM), that is, PC=0x81008000 at this time, then r0 is 0x81008000.
*
* Pay attention to the difference between ldr and adr, see the following code snippet:
* ldr r0, _start
* adr r0, _start
* ldr r0, =_start
* nop
* mov pc, lr
* _start:
* nop
* Here is the disassembly result:
* 0c008000 <_start-0x14>:
* c008000: e59f000c ldr r0, [pc, #12] ; c008014 <_start>
* c008004: e28f0008 add r0, pc, #8 ; 0x8
* c008008: e59f0008 ldr r0, [pc, #8] ; c008018<_start+0x4>
* c00800c: e1a00000 nop (mov r0,r0)
* c008010: e1a0f00e mov pc, lr
*
* 0c008014 <_start>:
* c008014: e1a00000nop (mov r0,r0)
*
* Analysis:
* ldr r0, _start
* Read the value from the memory address _start.After executing this, r0 = 0xe1a00000
*
* adr r0, _start
* takes the address of _start to r0, but look at the decompiled result, it is position independent.In fact, it is a relative position.For example, this code runs at 0x0c008000,
* then adr r0, _start gets r0 = 0x0c008014; if it runs at address 0, it is 0x00000014.That is, the current PC value plus the offset of _start.
*
* ldr r0, =_start
* This gets the absolute address of the label _start.This absolute address is determined at link time.It seems that this is just an instruction, but it takes up 2 32bit spaces,
* one is the instruction and the other is the data of _start (because the value of _start cannot be determined at compile time, so you cannot use mov directlyThe instruction to assign a 32bit constant to r0,
* Therefore, an extra space is needed to store the real data of _start, which is determined at the time of link, here is 0x0c008014).
* So it can be seen that this is absolute addressing, no matter where this code runs, its result is r0 = 0x0c008014
边栏推荐
- C language implementation guess Numbers (with source code, can be directly run)
- OpenMLDB v0.5.0 发布 | 性能、成本、灵活性再攀高峰
- 黑马大事件项目
- MSP430学习总结——时钟UCS
- 蓝牙技术-简介
- Building a data ecology for feature engineering - Embrace the open source ecology, OpenMLDB fully opens up the MLOps ecological tool chain
- 物联网基础知识学习
- SearchGuard证书配置
- 支付牌照是什么意思
- Thesis unscramble TransFG: A Transformer Architecture for Fine - grained Recognition
猜你喜欢
随机推荐
华为IOT平台温度过高时自动关闭设备场景试用
Minutes of OpenMLDB Meetup No.2
STM32学习总结(一)——时钟RCC
Day 76
vim 编辑解决中文乱码问题
USB中用NRZI来编码数据
无效的修订:3.18.1-g262b901-dirty
实时特征计算平台架构方法论和基于 OpenMLDB 的实践
js常用方法对象及属性
Day 86
精彩联动 | OpenMLDB Pulsar Connector原理和实操
何凯明新作ViTDET:目标检测领域,颠覆分层backbone理念
Js method commonly used objects and attributes
STM32-串口常用寄存器和库函数及配置串口步骤
使用adb命令管理应用
贡献者任务第三期精彩来袭
The whole process of Tinker access --- Compilation
字节(byte)和位(bit)
构建面向特征工程的数据生态 ——拥抱开源生态,OpenMLDB全面打通MLOps生态工具链
vscode插件开发——代码提示、代码补全、代码分析