arm - 在 Arm 汇编中为斐波那契创建一个 while 循环
问题描述
我试图让用户输入一个斐波那契术语,我使用迭代来找出给定术语的值。我想使用一个while循环来做到这一点,但是它说“startLoop”和“endLoop”是错误的指令。我对 ARM Assembly 很陌生,所以如果我的代码有什么问题,请告诉我。循环从“@ While index is less than given value”的注释开始
inputMessage: .asciz "Enter a fibonacci term: "
scanFormat: .asciz "%d"
output: .asciz "You entered: %d \n"
returnValue: .asciz "Fibonacci term: %d"
.text
.align 2
.global main
.type main, %function
main:
mov r10, lr
@ create input value
ldr r0, =inputMessage
bl printf
mov lr, r10
@ recieve input from user
add sp, sp, #4 @ Reserve space for number entry ???
ldr r0, =scanFormat @ Run scanFormat
mov r1, sp
bl scanf
mov lr, r10
@ print user input
ldr r1, [sp] @ read first number
add sp, sp, #4 @ restore sp
ldr r0, =output @ print output
bl printf
mov lr, r10
@ Initialize first and second fibonacci values
mov r2, #1
mov r3, #1
@ Initialize index counter
mov r4, #0
@ Initialize return value
mov r5, #0
@ While index is less than given value
startLoop
cmp r1, r4
bge endLoop
add r5, r2, r3
mov r2, r3
mov r3, r5
add r4, #1
B startLoop
endLoop
@ print fibonacci term
ldr r5, =returnValue
bl printf
mov lr, r10
bx lr
解决方案
推荐阅读
- kotlin - 无法在 kotlin 中将 text2 设置为 milliuntilfinish ... valueof 显示错误
- javascript - 无法从 rails 中的 vendor 文件夹加载资产
- javascript - HUGO:由于 MIME 类型(“text/html”)不匹配而被阻止(X-Content-Type-Options: nosniff)
- ios - 从 Swift 中的 Share Extension 获取数据
- r - 将新值添加到 R 中的嵌套列表中
- excel - 更改为动态 vba
- c# - C# - 如何使用需要泛型类型的泛型类型创建实例?
- r - R中的(业余)数据操作:变量级别作为新列,其值来自另一列
- javascript - 当我删除 index.css 时,Create-react-app 中断
- swift - CMTime在编码和解码媒体之外有任何实际应用吗