基本格式
语法
Label | Symbolic Labeling of an assembler address |
---|---|
mnemonic | Symbolic description of the operation |
operands | 操作数 Contains of variables or addresses if necessary |
comments | 用; 表示,Optional Field |
地址
Endianess (Bit Order)
- The ARM processor is little endian by default; and can be programmed to operate as big endian
Wtite Assembly for ARM
回顾
ISA (Istruction Set Architecture)
- 信息的获取和存储
-
Memory
-
Register
-
I/O Devices
- 信息的处理
-
Assembly-Language Instructions
-
Hardware Process Actions
RISC
- Load
- Store
- Data Path & Control Unit
- Instruction Pipelines
重要单元结构
Arm Register File
- PC 存储下一条指令的地址
Cortex-M Memory Map (内存图)
-
32位支持$2^{32} = 2^{30} \times 2^2 =4G$ 内存
-
Code、Data、I/O 共用内存
-
数据类型: Bytes, words, halfwords
-
内存地址类型: Bytes
- Vendor Specifc: 针对某个厂商的
Data Path & Control Unit
Instructions
-
Arithmatic、Logic、Comparison Operation
-
Data Movement between Registers
Registers
-
Saved Register: R4-R11, hold variables
-
Temporary Register: R0-R3, R12, hold intermediate values
指令 助记符 标志位 标签
ARM Cortex-M的汇编指令
MOV | 寄存器之间移动 |
---|---|
MVN | MOVE and NOT, 取反并移动 |
LDR | LOAD, 从内存(操作数2)中加载到寄存器(操作数1)中 |
STR | STORE, 从寄存器(操作数1)中存储到内存(操作数2)中 |
[a,b] | 地址a+b |
ADR(伪指令) | Address, 让寄存器指向后面的地址 |
ADD | 相加 |
ADC | 带进位的加法运算 |
SUB | 相减 |
SBC | 带进位的减法运算 |
AND | 按位与 |
BIC(Bit Clean) | 按位与非,将第一个操作数中对应的第二个操作数中为1的位清零 |
ORR | 按位或 |
LSL(Logical Shift Left) | 左移 |
LSR | 右移 |
MUL | 乘法($32bit \times 32bit = 32bit$),结果没有影响 |
CMP | 比较 |
EOR | Exclusive OR, 异或 |
ARM ALU*
Conditional Flag (CNVZ)
- 标识位解释
N | Negative, 负标志位 |
---|---|
Z | Zero, 零标志位(若相等,零标志位=1) |
C | Carry, 进位标志位 |
V | Overflow, 溢出标志位 |
- 助记符
NE | 不等于 |
---|---|
EQ | 等于 |
MI | Morse Code International, 当标志位N=1时执行指令 |
- 示例(Conditional Opcode)
|
|
Branching
|
|
用汇编写C
- MAX函数
|
|
|
|
- 循环
|
|
|
|
- 指数运算
|
|
|
|