一、思维导图
二、练习
实现三个灯闪烁
汇编代码
.text
.global _start
_start:
@使能GPIOE和F时钟
LDR r0,=0x50000A28
LDR r1,[R0]
ORR R1,R1,#(0X3<<4)
STR R1,[R0]
@配置GPIOE和F的MODER寄存器
LDR r0,=0x50006000 @GPIOE
LDR R1,=0X50007000 @GPIOF
LDR R2,[R0]
BIC R2,R2,#(0X3<<20)
BIC R2,R2,#(0X3<<16)
ORR R2,R2,#(0X1<<20)
ORR R2,R2,#(0X1<<16)
STR R2,[R0]
LDR R2,[R1]
BIC R2,R2,#(0X3<<20)
ORR R2,R2,#(0X1<<20)
STR R2,[R1]
@配置GPIOE和F的OTYPER寄存器
LDR r0,=0x50006004 @GPIOE
LDR R1,=0X50007004 @GPIOF
LDR R2,[R0]
BIC R2,R2,#(0X1<<10)
BIC R2,R2,#(0X1<<8)
STR R2,[R0]
LDR R2,[R1]
BIC R2,R2,#(0X1<<10)
STR R2,[R1]
@配置GPIOE和F的OSPEEDR寄存器
LDR r0,=0x50006008 @GPIOE
LDR R1,=0X50007008 @GPIOF
LDR R2,[R0].text
.global _start
_start:
@使能GPIOE和F时钟
LDR r0,=0x50000A28
LDR r1,[R0]
ORR R1,R1,#(0X3<<4)
STR R1,[R0]
@配置GPIOE和F的MODER寄存器
LDR r0,=0x50006000 @GPIOE
LDR R1,=0X50007000 @GPIOF
LDR R2,[R0]
BIC R2,R2,#(0X3<<20)
BIC R2,R2,#(0X3<<16)
ORR R2,R2,#(0X1<<20)
ORR R2,R2,#(0X1<<16)
STR R2,[R0]
LDR R2,[R1]
BIC R2,R2,#(0X3<<20)
ORR R2,R2,#(0X1<<20)
STR R2,[R1]
@配置GPIOE和F的OTYPER寄存器
LDR r0,=0x50006004 @GPIOE
LDR R1,=0X50007004 @GPIOF
LDR R2,[R0]
BIC R2,R2,#(0X1<<10)
BIC R2,R2,#(0X1<<8)
STR R2,[R0]
BIC R2,R2,#(0X3<<20)
BIC R2,R2,#(0X3<<16)
STR R2,[R0]
LDR R2,[R1]
BIC R2,R2,#(0X3<<20)
STR R2,[R1]
@配置GPIOE和F的PUPDR寄存器
LDR r0,=0x5000600C @GPIOE
LDR R1,=0X5000700C @GPIOF
LDR R2,[R0]
BIC R2,R2,#(0X3<<20)
BIC R2,R2,#(0X3<<16)
STR R2,[R0]
LDR R2,[R1]
BIC R2,R2,#(0X3<<20)
STR R2,[R1]
LOOP:
BL LED_ON
BL DELAY
BL LED_OFF
BL DELAY
B LOOP
LED_ON:
@GPIOE
LDR r0,=0x50006014
LDR r1,[R0]
ORR R1,R1,#(0X1<<10)
ORR R1,R1,#(0X1<<8)
STR R1,[R0]
@GPIOF
LDR r0,=0x50007014
LDR r1,[R0]
ORR R1,R1,#(0X1<<10)
STR R1,[R0]
MOV PC,LR
LED_OFF:
@GPIOE
LDR R0,=0x50006014
LDR R1,[R0]
BIC R1,R1,#(0X1<<10)
BIC R1,R1,#(0X1<<8)
STR R1,[R0]
@GPIOF
LDR r0,=0x50007014
LDR r1,[R0]
BIC R1,R1,#(0X1<<10)
STR R1,[R0]
MOV PC,LR
DELAY:
LDR R3,=0X10000000
MM:
CMP R3,#0
SUBNE R3,R3,#1
BNE MM
MOV PC,LR
.end
Makefile
NAME=asm-led
CROSS_COMPILE = arm-linux-gnueabihf-
CC = $(CROSS_COMPILE)gcc
LD = $(CROSS_COMPILE)ld
OBJCOPY = $(CROSS_COMPILE)objcopy
OBJDUMP = $(CROSS_COMPILE)objdump
all:
$(CC) -O0 -g -c $(NAME).S -o $(NAME).o
$(LD) -Ttext=0xC0008000 $(NAME).o -o $(NAME).elf
$(OBJCOPY) -O binary $(NAME).elf $(NAME).bin
$(OBJDUMP) -D $(NAME).elf > $(NAME).dis
clean:
rm -rf *.elf *.bin *.o *.dis
install:
sudo cp $(NAME).bin /mnt/hgfs/share/