繁体   English   中英

MIPS-装配数减少,但进入无限循环

[英]MIPS - Assembly count goes down but goes into infinite loop

我正在尝试从用户输入的数字开始递减计数,并希望显示该数字和0之间的所有整数。我相信我的输出会下降,但随后会在1处进入无限循环。似乎永远不会为零。

我刚刚开始学习汇编,所以如果这是一个不好的问题,我会提前道歉。

谢谢

这是我的代码:

.globl  main

.data
    msg: .asciiz "Input a number: "
    x: .word 1

    .text
main:

    li  $v0,4       # display the first message
    la  $a0, msg
    syscall 

    li  $v0, 5      # call for an input read, stores in $v0
    syscall

    move    $t0, $v0    # move the input to a temporary register
    lw  $t1, x          # loads x into $t1 registers

# Show Output
doLoop:
    sub $v0, $t0, $t1   # subtracts 1 from given input stores in $v0

    move $s0, $v0

    li $v0, 1       # Prepares to print integer
    move $a0, $v0
    syscall

    bgt $a0, 0, doLoop

    li  $v0,10      # load the "exit" number into register $v0
    syscall 

这似乎对我来说是成功的诀窍,我一直在搞砸我在寄存器中放置常量的位置。 因此,每次我尝试打印寄存器时都包含一个1。

doLoop: 

sub     $t2, $t0, $t1   # subtracts 1 from given input stores in $v0

li  $v0, 1      
move    $a0, $t2    # Places answer in $a0
la  $v0, 1
syscall

move    $t0, $t2    
bgt $a0, 0, doLoop

li  $v0,10      # load the "exit" number into register $v0
syscall 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM