The use of = sign in ARM assembly
Load constants
All AArch64 instructions are 32-bits long…
ARM instruction 只有 32 bits 長,需要借助 pseudo instruction: adr, ldr 的輔助,例如載入常數
1 | ldr rd, =constant |
ldr 會依據情況轉換成 mov, mvn, ldr [pc, #offset] 等指令,= 用意是從 literal pool 找出該常數,若沒有就放入 literal pool。
Source code
1
2
3ldr r0, =0xff
ldr r1, =0xffffffff
ldr r2, =0xf00000ffDisassembly
1
2
3mov r0, #0xff
mvn r1, #0x00
ldr r2, [pc,
adr 在 entry.S 用意是將 sys_call_table 地址載入到 stbl,再來藉由 ldr x16, [stbl, scno, lsl #3] 載入 syscall 地址。
ADRaccepts a PC-relative expression, that is, a label with an optional offset where the address of the label is relative to the PC.
1 | sc_nr .req x25 // number of system calls |
Reference
Addressing modes
The address for a load or store is formed from two parts: a value from a base register, and an offset.
The offset takes one of three formats:
- Immediate
- Register
- Scaled register
The offset and base register can be used in three different ways to form the memory address.
- Offset
- Pre-indexed
- Post-indexed
直接看上課簡報認識指令