了解ARM“ LDR”助记符

时间:2018-12-12 20:43:58

标签: assembly raspberry-pi arm

我有以下汇编代码来切换树莓派的LED

.section .init
.globl _start
_start:

@ Base adress for gpio controller
ldr r0,=0x20200000

@ Store a "0x01" to enable the output
mov r1,#1

@ Shift the "0x01" 12 places to acces gpio 24 (Bit 14 to 12)
lsl r1,#12

@ Copy the value to the register r0 + 8 (GPFSEL2)
str r1,[r0,#8]

@ Store a "0x01" to turn the led on
mov r1,#1
lsl r1,#24

@ Copy the value to the register r0 + 28 (GPSET0)
str r1,[r0,#28]

loop$:
b loop$

我用arm-none-eabi-toolchain编译它,并通过objdump创建kernel.img,以便在我的树莓派上而不是原始内核上运行它。 拆卸图像后我得到了拆卸

反汇编:

LDR R0, [PC, #0x18]
MOV R1, #1
LSL R1, R1, #0xC
STR R1, [R0, #8]
MOV R1, #1
LSL R1, R1, #0x18
STR R1, [R0, #0x1C]
B   #0x1C

图片:

18 00 9F E5 01 10 A0 E3 01 16 A0 E1 08 10 80 E5 01 10 A0 E3 01 1C A0 E1 1C 10 80 E5 FE FF FF EA

有人可以解释为什么行ldr r0,=0x20200000转换为LDR R0, [PC, #0x18]吗?如果我对这行的理解正确,寄存器r0将从存储单元PC + 0x18的值中加载。这如何产生GPIO控制器的地址?

0 个答案:

没有答案