本文介绍了不工作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)$呼应?总是显示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汇编语言菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-08 12:52