当前位置:网站首页>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指令实现,具体可以参考如下文章:
边栏推荐
猜你喜欢
随机推荐
数据偏见的背后是什么
checkPermissions Missing write access to /usr/local/lib
【我的电赛日记(完结)---2021全国大学生电子设计竞赛全国一等奖】A题:信号失真度测量装置
vscode编译keil工程,烧录程序
MySQL知识总结 (十一) MySql 日志,数据备份,数据恢复
MySQL知识总结 (四) 事务
两个surfaceview的重叠效果类似直播效果中的视频和讲义实践
神经网络可以解决一切问题吗:一场知乎辩论的整理
流,向量场,和微分方程
Visual studio代码中有红色波浪线解决办法
PyTorch⑤---卷积神经网络_卷积层
Seq2Seq模型PyTorch版本
【使用Pytorch实现ResNet网络模型:ResNet50、ResNet101和ResNet152】
The problem that UIWindow's makeKeyAndVisible does not call viewDidLoad of rootviewController
[论文阅读] ACT: An Attentive Convolutional Transformer for Efficient Text Classification
内存申请(malloc)和释放(free)之下篇
Word2vec词向量
Redis database related commands
LLVM系列第二十一章:写一个简单的Loop Pass
2. Basic use RecyclerView