本文介绍了ARM 汇编语言菜单不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
/*menu_prompt*/
.balign 4
menu_prompt: .asciz "Choose which problem.\nType 1 for Problem 1\nType 2 for Pr$
/*scanner*/
.balign 4
scan_pattern_int: .asciz "%d"
scan_read: .word 0
.balign 4
return: .word 0
.global main
main:
ldr r0, address_of_return
str lr, [r1]
ldr r0, address_of_menu_prompt
bl printf
ldr r0, address_of_scan_pattern_int
ldr r1, address_of_scan_read
bl scanf
ldr r1, [r1]
str lr, [r1]
ldr r0, address_of_menu_prompt
bl printf
ldr r0, address_of_scan_pattern_int
ldr r1, address_of_scan_read
bl scanf
ldr r1, [r1]
cmp r1, #1
beq in_prob_1
cmp r1, #2
beq in_prob_2
cmp r1, #3
beq in_prob_3
in_prob_1:
mov r0, #100
bal end
in_prob_2:
mov r0, #200
bal end
in_prob_3:
mov r0, #300
bal end
end:
ldr lr, address_of_return
ldr lr, [lr]
bx lr
address_of_menu_prompt: .word menu_prompt
address_of_scan_pattern_int: .word scan_pattern_int
address_of_scan_read: .word scan_read
address_of_return: .word return
在我运行程序后,无论我选择哪个输入(1,2 或 3)echo$?总是显示 r0 为 139,我不知道为什么.如果我选择 1 r0 应该持有 100,2 r0 应该持有 200,3 和 r0 应该持有 300.
after i run the program no matter which input i choose (1,2, or 3) echo$? always shows that r0 holds 139, i'm not sure why. if i choose 1 r0 should hold 100, 2 r0 should hold 200, 3 and r0 should hold 300.
推荐答案
scanf
不需要保留 r1
的内容,因为你已经通过了每个 ARM 程序呼叫标准.您应该在分支到 scanf
后重新加载 r1
.
scanf
doesn't need to leave the contents of r1
as you've passed per ARM Procedure Call Standard. You should reload r1
after branching to scanf
.
这篇关于ARM 汇编语言菜单不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!