所以我要做的是让我的微控制器上的LED使用循环来回闪烁。到目前为止,我已经能够使用此代码使 LED 从右向左闪烁
.equ LEDS, 0x10000010
.text
.global _start
_start: movia r2, LEDS
movi r3, 0b10000000
movi r4, 0x7FFF
slli r4, r4, 3
add r4, r4, r4
load: movi r5, 0b00000001
loop: stw r5, 0(r2)
mov r6, r0
count: addi r6, r6, 1
bne r6, r4, count
beq r5, r3, load
roli r5, r5, 1
br loop
并使用此代码从左到右闪烁
.equ LEDS, 0x10000010
.text
.global _start
_start: movia r2, LEDS
movi r3, 0b00000001
movi r4, 0x7FFF
slli r4, r4, 3
add r4, r4, r4
load: movi r5, 0b10000000
loop: stw r5, 0(r2)
mov r6, r0
count: addi r6, r6, 1
bne r6, r4, count
beq r5, r3, load
roli r5, r5, -1
br loop
我遇到的麻烦是将两者结合起来,以便它从左到右闪烁,然后在循环中从右到左闪烁。是否需要更改环路寄存器或计数?
当前代码分支到load
,当r5
等于 r3
时。相反,它应该分支到另一组代码。换句话说,从右向左移动后,分支到从左到右闪烁LED的代码,反之亦然。生成的代码如下所示:
.equ LEDS, 0x10000010
.text
.global _start
_start: movia r2, LEDS
movi r4, 0x7FFF
slli r4, r4, 3
add r4, r4, r4
goleft: movi r3, 0b10000000
movi r5, 0b00000001
lloop: stw r5, 0(r2)
mov r6, r0
lcount: addi r6, r6, 1
bne r6, r4, lcount
beq r5, r3, goright
roli r5, r5, 1
br lloop
goright: movi r3, 0b00000001
movi r5, 0b10000000
rloop: stw r5, 0(r2)
mov r6, r0
rcount: addi r6, r6, 1
bne r6, r4, rcount
beq r5, r3, goleft
roli r5, r5, -1
br rloop