2016-02-14 71 views
1
.data 
prompt1: .asciiz "Enter your first number:" 
prompt2: .asciiz "Enter your second number:" 
.text 
main: 

#displays "Enter your first number:" 
li $v0 4 
la $a0 prompt1 
syscall 

#Reads the next int and stores in $s0 
li $v0 5 
syscall 
move $s0 $v0 

#displays "Enter your second number:" 
li $v0 4 
la $a0 prompt2 
syscall 

#Reads next int and stores in $s1 
li $v0 5 
syscall 
move $s1 $v0 


#Divides user input $s0/$s1 and stores in $t0 
div $t0 $s0 $s1 
syscall 


#Print value of $t0 
li $v0 1 
move $t0 $v0 
syscall 

li $v0 10 
syscall 

我的代码的目标是要求用户输入2个输入并将它们分开。但是,当我在输入“1”中运行程序时,我的输出是一个非常高的数字。我想在MARS MIPS中划分,但它给了我错误的答案

回答

0

我看到一对夫妇的事情:

  1. 还有的除法指令后,一个额外的系统调用。
  2. 当您想要打印$ t0的值时,请记住print_int syscall将打印$ a0中的任何内容,而不是$ t0。现在,$ v0(它是1)的内容被移动到$ t0,但是print_int syscall正在打印$ a0,这是垃圾。

试试这个(除了上面去除多余的系统调用):

#Print value of $t0 
li $v0 1 
move $a0 $t0 
syscall 

希望有所帮助。

相关问题