assembly - ARM Assembly increasing number with push button
问题描述
I want to ask you a question about ARM Assembly,
.global _start
_start:
.equ COOL, 0x393f3f38
.equ KEY_BASE_ADRESS, 0xFF200050
.equ S_SEGMENT_BASE_ADRESS, 0xFF200020
LDR R1, =KEY_BASE_ADRESS
LDR R2, =S_SEGMENT_BASE_ADRESS
MOV R8, #0x0000000F // Register that holds the number
MOV R5, #0// R5 holds the number obtanined from player
CHECK_SWITCH:
LDR R6, [R1]
CMP R6, #2
BEQ ADD
B CHECK_SWITCH
ADD:
ADD R5, R5, #1
CMP R5, R8
BNE CHECK_SWITCH
DISPLAY:
LDR R5, =COOL
STR R5, [R2]
.end
I am trying make a game (guess the number but not very meaningfull so far) for de1-soc.I want to increase "1" player's number in R5, when he pushes KEY1. Also 7 segment will display "COOL" when the number in R5 equals to the R8. Problem is when I push and release the KEY1, program executes so fast and finish the program. What I need is, every push and and release KEY1, should increase only "1" How can I handle this? Thanks!
By the way you can execute code from here https://cpulator.01xz.net/?sys=arm-de1soc
解决方案
您的代码流是
check for key press:
while key not pressed goto check for key press
add one
go to check for key press:
一旦开关改变状态然后按键被按下它就不再等待它只是不断地通过外部(添加一个以检查按键)循环。
你想要的是检查未按下状态作为外循环中的某处
check for key not pressed:
while key pressed goto check for key not pressed
check for key press:
while key not pressed goto check for key press
add one
go to check for key not pressed
或者
check for key press:
while key not pressed goto check for key press
check for key not pressed:
while key pressed goto check for key not pressed
add one
go to check for key press
或者
check for key press:
while key not pressed goto check for key press
add one
check for key not pressed:
while key pressed goto check for key not pressed
goto check for key press
您可以将加一和检查最大计数分成两件事,然后将其洒在...
但是,一旦开关位断言,您将撕开外循环,因为您不能足够快地将开关放回原处。如果要计算开关的单独按下次数,则需要轮询循环中的断言和取消断言状态。
还可以考虑使用 tst 而不是 cmp。在文档中查找。
推荐阅读
- python - 如何从python中的元组中提取数字和字符
- react-native - 升级到 npm7 但库中断太多
- html - 为什么更改 div 上的字体大小会更改其高度?
- android - 使 Android 应用仅适用于 Playstore 上的工作资料
- firebase - HMS 华为管理服务
- flutter - 从 dart 向 wit.ai 发送分块音频请求
- java - 如何使用 Apache httpclient5 从 SimpleHttpResponse 获取 HttpEntity
- angular - Angular Unit Test - 如何获取对组件范围提供者的引用?
- c - 在 zephyr 上使用 west build-flash
- swift - 将 combine 的 Future 映射到新的输出和失败