ARM汇编。 While循环无法正常工作

时间:2018-10-22 20:03:32

标签: assembly arm

因此,我的分配工作比仅从while循环中打印数字更为复杂,但是我什至无法使while循环正常工作,因此我现在就开始进行工作。我正在尝试获取一个小于10的用户输入,然后从那里开始并从输入输出每个数字,直到10。例如:输入为7,输出为7,8,9,10。 但是它陷入了无限循环。 r1确实会增加,但输出始终为1(即使原始数字不是1)。我到底做了什么?

.global main

main:

prompt:
    ldr r0, =strInputPrompt @ Put the address of my string into the first parameter
    bl printf       @ Cal the C print to display input prompt

get_input:
    ldr r0, =numInputPattern
    sub sp, sp, #4      @ update stack pointer to new loc
    mov r1, sp      @ put address into r1 for read
    bl scanf        @ scan keyboard
    ldr r1, [sp, #0]    @ The character is on the stack
    add sp, sp, #4      @ Reset the stack

    cmp r1, #10     @ compares user num to 10 and 0,
    bgt myexit      @ and if it is not in between those,
    cmp r1, #0      @ it terminates program
    ble myexit

display:
    ldr r0, =numsumstring   @loads r0 with string
    bl printf       @prints r0
loop:
    cmp r1, #10
    bgt myexit      @if value in r1 is > 10, exit
    ldr r0, = printline
    bl printf
    add r1,r1,#1    @add 1 to r1
    b loop

myexit:
    mov r7, #0x01   @ returns control to OS
    svc 0   

.data

    .balign 4
    numsumstring: .asciz "Number \t Sum\n\n"

    .balign 4
    numInputPattern: .asciz "%d"

    .balign 4
    printline: .asciz "value is %d \n"

    .balign 4
    strInputPrompt: .asciz "Input the number: "


.global printf
.global scanf

0 个答案:

没有答案
相关问题