您可以通过另一种方式间接而不是直接地做到这一点:
.data
.balign 4
value: .word 0x6c617669
.text
.global main
main:
push {lr} /* save lr value on stack */
ldr r0, address_of_value /* r0 = &value */
ldr r0, [r0] /* r0 = *r0 = value */
pop {lr} /* load lr (R14) register from stack */
bx lr /* return from main using lr */
address_of_value: .word value
R0 寄存器包含 32 位值,您可以看到调试此代码:
(gdb) start
Temporary breakpoint 1 at 0x103ec
Starting program: /home/pi/asm/kk
Temporary breakpoint 1, 0x000103ec in main ()
(gdb) disassemble
Dump of assembler code for function main:
0x000103e8 <+0>: push {lr} ; (str lr, [sp, #-4]!)
=> 0x000103ec <+4>: ldr r0, [pc, #8] ; 0x103fc <address_of_value>
0x000103f0 <+8>: ldr r0, [r0]
0x000103f4 <+12>: pop {lr} ; (ldr lr, [sp], #4)
0x000103f8 <+16>: bx lr
End of assembler dump.
(gdb) info registers r0
r0 0x1 1
(gdb) stepi
0x000103f0 in main ()
(gdb) stepi
0x000103f4 in main ()
(gdb) disassemble
Dump of assembler code for function main:
0x000103e8 <+0>: push {lr} ; (str lr, [sp, #-4]!)
0x000103ec <+4>: ldr r0, [pc, #8] ; 0x103fc <address_of_value>
0x000103f0 <+8>: ldr r0, [r0]
=> 0x000103f4 <+12>: pop {lr} ; (ldr lr, [sp], #4)
0x000103f8 <+16>: bx lr
End of assembler dump.
(gdb) info registers r0
r0 0x6c617669 1818326633
问候。