ARM作业1

2023-12-21 22:05:07

汇编实现三个灯闪烁

汇编代码:



.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

运行结果:

思维导图:

文章来源:https://blog.csdn.net/qq_56986199/article/details/135138597
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。