2016-02-14 68 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 

希望有所幫助。

相關問題