ldr伪指令的第二个操作数之前有个=,意思是第一个操作书 = 第二个操作数,相当明了
核心就在于对于用.word指令在.text段里另外定义一段内存,用ldr r0,[pc + x(可以算出.text段里的内存地址)]这种基于PC的偏移量方式加载内存里的内容到寄存器
看下源代码和反汇编的结果就清楚了
伪指令用于大的常数:
源代码:
top:
ldr r0,=
add r1,r2,r3
eor r1,r2,r3
eor r1,r2,r3
bottom:
b top
反汇编:
prebuilts/gcc/linux-x86/arm/arm-eabi-./bin$ ./arm-eabi-objdump -d test.o test.o: file format elf32-littlearm Disassembly of section .text: <top>:
: e59f000c ldr r0, [pc, #] ; 14 <bottom+0x4>
: e0821003 add r1, r2, r3
: e0221003 eor r1, r2, r3
c: e0221003 eor r1, r2, r3 <bottom>:
: eafffffa b <top>
: 00bc614e .word 0x00bc614e
伪指令用于标签:
源代码:
top:
ldr r0,=bottom
add r1,r2,r3
eor r1,r2,r3
eor r1,r2,r3
bottom:
b top
反汇编:
prebuilts/gcc/linux-x86/arm/arm-eabi-./bin$ ./arm-eabi-objdump -d test.o test.o: file format elf32-littlearm Disassembly of section .text: <top>:
: e59f000c ldr r0, [pc, #] ; 14 <bottom+0x4>
: e0821003 add r1, r2, r3
: e0221003 eor r1, r2, r3
c: e0221003 eor r1, r2, r3 <bottom>:
: eafffffa b <top>
: .word 0x00000010
ldr指令用于常数:
源代码:
top:
ldr r0,[r0]
add r1,r2,r3
eor r1,r2,r3
eor r1,r2,r3
bottom:
b top
反汇编:
prebuilts/gcc/linux-x86/arm/arm-eabi-./bin$ ./arm-eabi-objdump -d test.o test.o: file format elf32-littlearm Disassembly of section .text: <top>:
: e5900000 ldr r0, [r0]
: e0821003 add r1, r2, r3
: e0221003 eor r1, r2, r3
c: e0221003 eor r1, r2, r3 <bottom>:
: eafffffa b <top>
ldr指令用于标签:
源代码:
top:
ldr r0,bottom
add r1,r2,r3
eor r1,r2,r3
eor r1,r2,r3
bottom:
b top
反汇编:
prebuilts/gcc/linux-x86/arm/arm-eabi-./bin$ ./arm-eabi-objdump -d test.o test.o: file format elf32-littlearm Disassembly of section .text: <top>:
: e59f0008 ldr r0, [pc, #] ; 10 <bottom>
: e0821003 add r1, r2, r3
: e0221003 eor r1, r2, r3
c: e0221003 eor r1, r2, r3 <bottom>:
: eafffffa b <top>