ARM 汇编
ARM 汇编
Layout
label: instruction ;comment
label 字母、下划线和 $ 组成.
comment 所有在;后面的都认为是注释
instruction 指令
1 | |
Instruction Format
<op>{cond}{flags} Rd, Rn, Operand2
例如: ADD r0, r1, r2
三个字母的指令 - {cond} 可选,两个字母的状态码(condition code)
- {flags} 可选,附加标志位
- Rd 目标寄存器
- Rn 第一个寄存器
- Operand2 第二个寄存器或者操作数
Condition Code
在指令后面添加,允许指令在特定条件下执行。
AL - always
无条件执行,因此可以不用写 ADDAL 和 ADD 是等价的
NV - never。
AL 的反义词,带有该标记的指令不会执行。已经废弃。
EQ - equal
当 Z 标志为被设置过后,才会执行,如果 Z 标志位被清除,该行指令被忽略.
1
2
3
4
5
6
7MOV r0, #42 ;Write the value 42 into the register r0
MOV r1, #41 ;Write the value 41 into the register r1
CMP r0, r1 ;Compare the registers r0 and r1, update CPSR register
BEQ label ;This command will not be run, since Z = 0
MOV r1, #42 ;Write the value 42 into the register r1
CMP r0, r1 ;Compare r0 and r1, update the CPSR
BEQ label ;This command will be run, since Z = 1NE - not equal
EQ 的反义词,如果 Z 标志位被清除,则执行。如果 Z 标志位被设置过,该行指令被忽略
1
2
3
4
5
6
7MOV r0, #42 ;Write the value 42 into the register r0
MOV r1, #42 ;Write the value 42 into the register r1
CMP r0, r1 ;Compare the registers r0 and r1, update CPSR register
BNE label ;This command will not be run, since Z = 1
MOV r1, #41 ;Write the value 42 into the register r1
CMP r0, r1 ;Compare r0 and r1, update the CPSR
BNE label ;This command will be run, since Z = 0VS - overflow set
如果 overflow(v) 位被设置,该条件为 true。两个32位有符号数相加,可能会出一个33位的有符号数
VC - overflow clear
如果 overflow(v) 位被清除,该条件为 true。
MI - minus
如果 negative(N) 为被设置,该条件为 true
1
2
3
4MOV r0, #40
MOV r1, #42
SUBS r2, r0, r1 ; 40 – 42, the result is negative
BMI destination ; this portion of code is never executedPL - plus
如果 negative(N) 位被清除,该条件为 true。(<= 0)
CS - Carry Set
当一个在32位无符号数上的操作超出了32位的范围的时候,carry set 标志位设为 true
CC - Carry Clear
如果 Carry Flag(C) 被清除了,该条语句执行
HI - Higher
如果 Carry Flag(C) 被设置,并且结果非0(Z),该语句执行
LS - Lower or Same
如果 Carry Flag(C) 被清除,并且结果为0(Z),该语句执行
GE - Greater than or Equal
当有符号数,并且当 Negative(N) 和 Overflow(V) 相等的时候,该语句才有效
LT - Less Than
有符号数,并且当 Negative(V) 和 Overflow(V) 不相等的时候,该语句才有效。
LE - Less Than or Equal
像 LT, 如果 Negative(V) 和 Overflow(V) 不相等,或者 Zero(Z)标志位被设置了的时候,该语句才执行。
| CODE | MEANING | FLAGS |
|---|---|---|
| EQ | Equal equals Zero | Z |
| NE | Not Equal | !Z |
| VS | Overflow | V |
| VC | No overflow | !V |
| MI | Minus/negative | N |
| PL | Plus/positive or zero | !N |
| CS | Carryset/unsigned higher or same | C |
| CC | Carry clear/unsigned lower | !C |
| HI | Unsigned higher | C and !Z |
| LS | Unsigned lower or same | !C or Z |
| GE | Signed greater than or equal | N == V |
| LT | Signed less than | N != V |
| GT | Signed greater than | !Z and (N == V) |
| LE | Signed less than or equal | Z or (N != V) |
| AL | Always(default) | Any |
Updating Condition Flags
默认情况下,指令不更新条件标志。
当 S (ADDS, SBCS…) 标志位被设置后,指令才能更新标志位。
例外:比较指令会自动更新
1 | |