所以我想要完成的是让我的微控制器上的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
我遇到的麻烦是将两者合并,使其从左向右闪烁,然后在循环中从右向左闪烁。我是否需要在循环寄存器或计数中进行更改?
答案 0 :(得分:0)
当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