当前位置:网站首页>arm ldr系列指令
arm ldr系列指令
2022-08-02 14:08:00 【nginux】
目录
ldrb指令
1. 语法
armv7手册语法:
LDRB{<c>}{<q>} <Rt>, [<Rn> {, #+/-<imm>}] Offset: index==TRUE, wback==FALSE
LDRB{<c>}{<q>} <Rt>, [<Rn>, #+/-<imm>]! Pre-indexed: index==TRUE, wback==TRUE
LDRB{<c>}{<q>} <Rt>, [<Rn>], #+/-<imm> Post-indexed: index==FALSE, wback==TRUE
<Rt> The destination register.
<Rn> The base register. The SP can be used. For PC use see LDRB (literal) on page A8-418.
+/- Is + or omitted if the immediate offset is to be added to the base register value (add == TRUE), or – if
it is to be subtracted (add == FALSE). #0 and #-0 generate different instructions.
<imm> The immediate offset used for forming the address. For the offset addressing syntax, <imm> can be
omitted, meaning an offset of 0. Any value in the range 0-4095 is permitted.功能描述:
Load Register Byte (immediate) calculates an address from a base register value and an immediate offset, loads a
byte from memory, zero-extends it to form a 32-bit word, and writes it to a register. It can use offset, post-indexed,
or pre-indexed addressing. For information about memory accesses see Memory accesses on page A8-291.核心:从某个地址加载一个字节(Byte)到寄存器 Rt中,根据memory access方式不同分为:
- Offset addressing
- Pre-indexed addressing
- Post-indexed addressing
2. Memory access mode
Offset addressing:
Offset addressing:
The offset value is applied to an address obtained from the base register. The result is used as the address for the memory access. The value of the base register is unchanged. The assembly language syntax for this mode is: [<Rn>, <offset>]
Pre-indexed addressing :
Pre-indexed addressing
The offset value is applied to an address obtained from the base register. The result is used as the address for the memory access, and written back into the base register. The assembly language syntax for this mode is: [<Rn>, <offset>]!
Post-indexed addressing :
Post-indexed addressing
The address obtained from the base register is used, unchanged, as the address for the memory access. The offset value is applied to the address, and written back into the base register The assembly language syntax for this mode is: [<Rn>], <offset>
3. 详细说明
- Offset addressing:[Rn, offset]
说明:最终访问内存的地址 = Rn+offset,这种操作后Rn的值不会改变
- Pre-indexed addressing:[ Rn, offset] !
说明:最终访问内存的地址 = Rn+offset,这种操作后Rn的值 = Rn+offset,注意加载的值来自地址:Rn + offset的值(更新后),类似于++i。
- Post-indexed addressing :[Rn],offset
说明:最终访问内存的地址 = Rn,这种操作后Rn的值 = Rn+offset,跟pre-indexed的核心区别在于加载的值来自地址:Rn(更新前前),类似于i++
4. 实验验证:
通过实现一个c调用汇编的程序代码验证ldrb功能:
c程序:arm.c
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
extern void asm_strcpy(const char *src, char *dest);
int main(){
const char *s = "Hello World";
char tmp[32];
memset(tmp, 0, sizeof(tmp)/sizeof(char));
asm_strcpy(s, tmp);
printf("-----%s------\n", tmp);
}
~ 汇编程序:ldrb.S
.globl asm_strcpy
asm_strcpy:
loop:
ldrb r4, [r0, #1]!
cmp r4,#0
beq over
strb r4,[r1], #1
b loop
over:
mov pc,lr
.type asm_strcpy,%function编译:arm-linux-androideabi-gcc -o ldrb ldrb.S arm.c -pie -fPIE
运行:
D:\tmp>adb shell ldrb
-----ello World------
可以看到由于采用了[r0, #1] pre-indexed的memory access方式,r4寄存器加载的值来自于地址:r0 + 1。如果改成ldrb r4, [r0], #1,可正常输出Hello Wold,如下:
D:\tmp>adb shell ldrb
-----Hello World------
ldr指令
1.语法
Load Register (immediate) calculates an address from a base register value and an immediate offset, loads a word
from memory, and writes it to a register. It can use offset, post-indexed, or pre-indexed addressing. For information
about memory accesses see Memory accesses on page A8-291.
于ldrb的区别在于一次加载一个word长度的数据。arm32位中即32 bit的数据。
举例:
1. ldr r0, =0x00000001 @加载立即数1到寄存器r0,= 意思对变量取地址
2.
.globl get_int
get_int:
ldr r0, =abc @将0x10数值加载r0寄存器
mov pc,lr
.long abc
.equ abc, 0x10
ldrex指令
Load Register Exclusive calculates an address from a base register value and an immediate offset, loads a word from
memory, writes it to a register and:
• if the address has the Shared Memory attribute, marks the physical address as exclusive access for the
executing processor in a global monitor
• causes the executing processor to indicate an active exclusive access in the local monitor.
ldrex跟ldr核心区别实现原子操作,如内核的atomic_cmpxchg就是基于ldrex和strex指令实现,具体可以参考如下文章:
边栏推荐
- MySQL知识总结 (八) InnoDB的MVCC实现机制
- Enhanced Apktool reverse artifact
- Spark_DSL
- Win10 can't start WampServer icon is orange solution
- Redis-01-Nosql概述
- 关系代数、SQL与逻辑式语言
- In the Visual studio code solutions have red wavy lines
- LLVM系列第五章:全局变量Global Variable
- MySQL知识总结 (二) 存储引擎
- Manifest merger failed with multiple errors, see logs
猜你喜欢
随机推荐
The problem that UIWindow's makeKeyAndVisible does not call viewDidLoad of rootviewController
PyTorch(14)---使用现有的模型及其修改
MySQL知识总结 (六) MySQL调优
机器学习---监督学习、无监督学习
Enhanced Apktool reverse artifact
拥抱Jetpack之印象篇
再见篇:App专项技术优化
IllegalStateException: Room cannot verify the data integrity. Looks like you've changed schema but
[论文阅读] ACT: An Attentive Convolutional Transformer for Efficient Text Classification
spark写sql的方式
profiler network乱码
MySQL知识总结 (三) 索引
RN开发时遇到的问题
Ffmpeg交叉编译
VS2017中安装visual assist X插件
PyTorch(15)---模型保存和加载
图像配置分类及名词解释
使用flutter小记
It is not allowed to subscribe with a(n) xxx multiple times.Please create a fresh instance of xxx
可以拖拽的ViewGroup,仿微信拖拽缩放关闭









