LDM与STM指令详解


title: LDM与STM指令详解
date: 2019/2/26 17:58:00
toc: true

LDM与STM指令详解

指令形式如下,这里的存储方向是针对寄存器的

Load Multiple (LDM) and Store Multiple (STM) 
LDM{<cond>}<addressing_mode> Rn{!}, <registers>{^}
STM{<cond>}<addressing_mode> Rn{!}, <registers>{^}

LDM,加载寄存器列表

LDMIA R2, {R0-R3} ; Reload R0-R3 from temporary storage

STM,存储寄存器列表

STMIA R13, (R0-R3) ; Put R0-R3 into temporary storage
看下STR
STR R0, [R7, #0x7C] ; Store word from R0 to address R7 + 124
摘自汇编器指南
^ 为一个可选后缀,仅可用于 ARM 状态。 不可在用户模式或系统模
式下使用该后缀。 该后缀具有下列功能:
• 如果指令为 LDM (具有任何寻址模式)且 reglist 包含 pc
(r15),则除了正常的多寄存器传送外,还会将 SPSR 复制到
CPSR 中。 这是为了从异常处理程序返回。 请仅在异常模式下
使用此后缀。
• 否则,数据将被送入或送出用户模式寄存器,而不是当前模
式寄存器。

!

! 表示更新表示目标地址的寄存器在操作后是否更新这个表示地址的寄存器的值,如果没有则

  • LDM中,Rn不变
  • STM中,Rn不变

LDM ^

LDM{<cond>}<addressing_mode> <Rn>, <registers_without_pc>^

For an LDM instruction that does not load the PC, this indicates that User mode registers are to be loaded.

LDM{<cond>}<addressing_mode> <Rn>{!}, <registers_and_pc>^

For an LDM instruction that loads the PC, this indicates that the SPSR of the current mode iscopied to the CPSR.

  • 如果操作的寄存器有pc,则表示恢复spsr到cpsr,并跳转到pc,一般切换模式返回都需要这样,这个应该在异常模式下使用
  • 否则,表示存储的是用户模式的寄存器,比如我现在在异常模式,用这个方式的话**设置的是用户状态的寄存器sp**

STM ^

STM{<cond>}<addressing_mode> <Rn>, <registers>^

For an STM instruction, indicates that User mode registers are to be stored.

表示操作的是用户模式的寄存器,比如我现在在异常模式,用这个方式的话读取的的是用户状态的寄存器sp,也就是说将用户模式的sp存到某个地方

如果不用这个指令,想获取到用户的寄存器,我们需要切换到系统模式,因为系统模式和用户模式的sp是公用的

mark

MOVS

这里插入讲一下指令后跟个S,表示更新cpsr,MOVS PC,R14
This restores the PC (from R14_und) and CPSR (from SPSR_und) and returns to the instruction following
the Undefined instruction.

参考

关于指令,找不到的话看 ARM Architecture Reference Manual.pdf,直接google一下就有pdf

或者点击这里

中文的pdf RealView_ARM_汇编指南.pdf

原文地址:https://www.cnblogs.com/zongzi10010/p/10443652.html