【问题标题】:MIPS programming issueMIPS 编程问题
【发布时间】:2010-09-14 02:57:11
【问题描述】:

我在这里遇到了 MIPS 问题。我想要做的是让用户输入任何数字并让程序拼出数字中每个数字的名称。例如,用户输入 495,机器会拼出“四九五”。我正在尝试将数字的每个数字推入堆栈,然后将每个数字弹出。但是,弹出的数字并不是看起来被压入堆栈的数字。我对此感到很困惑,我希望有人能帮助我!我的代码的重要部分如下:

.text
main: li $v0, 5
syscall
move $t0, $v0
# store 10 into a register, because you can't divide by a constant
li $s1, 10

# now the input number is stored in $a0.  Time to divide by 10 a few times,
#and store each digit in a stack:
DivideLoop: # $s3 = $s0 / 10
div $t0, $s1
# this is the remainder of the division
mfhi $t3
mflo $t2
# move stack over by 4
addi $sp, $sp, -4
# store remainder in stack
sw $t3, 0($sp)
move $t0, $t2
beq $t2, $zero, PrintLoop
j DivideLoop

# This loop prints each digit
PrintLoop:
# check if stack is empty.  If so, branch to exit.
beq $sp, $zero, Exit
# put first word of stack into register $t0
lw $t0, 0($sp)
addi $sp, $sp, 4

【问题讨论】:

    标签: assembly loops stack mips


    【解决方案1】:

    解决了。原来 spim 和 xspim 完全是愚蠢的、错误的和错误的。我在火星上运行了这段代码,它运行得很好。我现在很高兴:)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-17
      • 1970-01-01
      • 2015-06-20
      • 2012-01-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多