ARM汇编指令基础

时间:2022-06-03 00:57:12

ARM汇编指令基础

1、ARM和THUMB指令

ARM和THUMB指令的区别

2、ARM运行模式

通过不同的中断来进入不同的模式

用户模式 User (usr) Mode is the normal execution state and cannot change the Operating Mode, except via theSWI instruction that switches Supervisor Mode.
快速中断模式 Fast Interrupt (fiq) Mode used to handle the highest interrupt source (typical just one).
中断模式 Interrupt (irq) Mode used for general-purpose interrupt handling.
 管理模式 Supervisor (svc) Mode for system start-up, invoked after CPU Reset.
异常模式 Abort (abt) Mode entered after a data or pre-fetch abort ( used for operating system abort handler).
未定义模式 Undefined (und) Mode entered on execution of a undefined instruction. May be used to emulate coprocessor functions.
系统模式 System (sys) Mode for privileged operating system functions, invoked by User Mode using theSWI instruction.
3、异常\中断向量表

CPU发生异常或者中断时,查找向量表进行指令跳转

4、程序状态寄存器PSR

ARM汇编指令基础

 The N, Z, C, and V 分别是Negative(为负), Zero(为零), Carry(进位/借位) and oVerflow(溢出)的英文缩写。

C位和V位的区别是,C位是无符号运算时候导致的,V位是有符号运算导致的。【注,参考ARM V5架构手册 Program Status Register章节】

The N, Z, C, and V (Negative, Zero, Carry and oVerflow) bits are collectively known as the condition code 
flags, often referred to as flags. 


5、数据类型

  • 双字(64bit)double word (64-bit) are accessed via the instructions LDRD and STRD.
  •     字(32bit)word (32-bit) are accessed via the instructions LDRD and STRD
  • 半字(16bit)halfword (16-bit) the instructions LDRH,LDRSH, and STRH.
  • 字节(8bit)byte (8-bit) are accessed via the instructions LDRB, LDRSB, and STRB.
6、ARM指令的条件码

{cond} Suffix Tested Status Flags Description
EQ Z set equal
NE Z clear not equal
CS/HS C set unsigned higher or same
CC/LO C clear unsigned lower
MI N set negative
PL N clear positive or zero
VS V set overflow
VC V clear no overflow
HI C set and Z clear unsigned higher
LS C clear or Z set unsigned lower or same
GE N equals V signed greater or equal
LT N not equal to V signed less than
GT Z clear AND (N equals V) signed greater than
LE Z set OR (N not equal to V) signed less than or equal
AL (ignored) always (usually omitted)

EQ Equal   等于

NE Not Equal不等于


GT Greater Than大于

GE Graeter or Equal大于或等于

LT Less   Than小于

LE Less or Equal小于或等于


VS V Set  V位置位

VC V Clear  V位清零


MI N Set  N位置位

PL N Clear  N位清零



     CMP    R5,#10   // compare R5 with 10
BHI lab1 // branch to lab1 if value in R5 is higher than 10
:
lab1:
TST R5,#10 // test content of R5 against 10
ADDEQ R6,#40 // add 40 to R6 if R5 contains 10

7、5种移位指令

LSR Logical Shift Right

 LSL Logical Shift Left

ASR  Arithmetic Shift Right

ROR Rotate Right

RRX Rotate Right Extend