汇编实现三个灯闪烁
汇编代码:
.text
.global _start
_start:
@设置GPIOE,GPIOF时钟使能
LDR R0,=0X50000A28
LDR R1,[R0]
ORR R1,R1,#(0x3<<4)
STR R1,[R0]
@设置PE10,PF10,PE8为输出
@LED1
LDR R0,=0X50006000
LDR R1,[R0]
ORR R1,R1,#(0X1<<20)
BIC R1,R1,#(0X1<<21)
@LED2
LDR R2,=0X50007000
LDR R3,[R2]
ORR R3,R3,#(0X1<<20)
BIC R3,R3,#(0X1<<21)
STR R3,[R2]
@LED3
ORR R1,R1,#(0X1<<16)
BIC R1,R1,#(0X1<<17)
STR R1,[R0]
@设置PE10,PF10,PE8为推挽输出
LDR R0,=0X50006004
LDR R1,[R0]
@LED1
BIC R1,R1,#(0X1<<10)
@LED2
LDR R2,=0X50007004
LDR R3,[R2]
BIC R3,R3,#(0X1<<10)
STR R3,[R2]
@LED3
BIC R1,R1,#(0X1<<8)
STR R1,[R0]
@设置PE10,PF10,PE8为低速输出
LDR R0,=0X50006008
LDR R1,[R0]
@LED1
BIC R1,R1,#(0X3<<20)
@LED2
LDR R2,=0X50006008
LDR R3,[R2]
BIC R3,R3,#(0X3<<20)
STR R3,[R2]
@LED3
BIC R1,R1,#(0X3<<16)
STR R1,[R0]
@设置PE10,PF10,PE8输出时无上拉下拉电阻
@LED1
LDR R0,=0X5000600C
LDR R1,[R0]
BIC R1,R1,#(0X3<<20)
@LED2
LDR R2,=0X5000600C
LDR R3,[R2]
BIC R3,R3,#(0X3<<20)
STR R3,[R2]
@LED3
BIC R1,R1,#(0X3<<16)
STR R1,[R0]
FLASH:
BL LED1_ON
BL LED2_OFF
BL LED3_ON
BL DELAY
BL LED1_OFF
BL LED2_ON
BL LED3_OFF
BL DELAY
B FLASH
@LED1亮
LED1_ON:
@设置PE10输出高电平
LDR R0,=0X50006014
LDR R1,[R0]
ORR R1,R1,#(0X1<<10)
STR R1,[R0]
MOV PC,LR
@LED1灭
LED1_OFF:
@设置PE10输出低电平
LDR R0,=0X50006014
LDR R1,[R0]
BIC R1,R1,#(0X1<<10)
STR R1,[R0]
MOV PC,LR
@LED2亮
LED2_ON:
@设置PE10输出高电平
LDR R0,=0X50007014
LDR R1,[R0]
ORR R1,R1,#(0X1<<10)
STR R1,[R0]
MOV PC,LR
@LED2灭
LED2_OFF:
@设置PE10输出低电平
LDR R0,=0X50007014
LDR R1,[R0]
BIC R1,R1,#(0X1<<10)
STR R1,[R0]
MOV PC,LR
@LED3亮
LED3_ON:
@设置PE8输出高电平
LDR R0,=0X50006014
LDR R1,[R0]
ORR R1,R1,#(0X1<<8)
STR R1,[R0]
MOV PC,LR
@LED3灭
LED3_OFF:
@设置PE8输出低电平
LDR R0,=0X50006014
LDR R1,[R0]
BIC R1,R1,#(0X1<<8)
STR R1,[R0]
MOV PC,LR
@延时
DELAY:
LDR R3,=0x10000000
MM:
CMP R3,#0
SUBNE R3,R3,#1
BNE MM
MOV PC,LR
.end
运行结果:
思维导图: