为什么我的节目"掉线?"?

时间:2015-09-18 17:41:19

标签: mips computer-architecture

我正在编写一个MIPS程序,该程序应该向用户询问两个数字,然后对这两个数字进行加,减,乘和除。我需要使用功能。每当我执行我的程序时,我的加/减功能都有效,但由于某种原因,当程序进入我的乘法函数时,它不会打印出答案而MARS给我的信息"掉到底部"。

enter image description here

.text       
main:
la $a0,prompt1  
li $v0,4
syscall #Asks for first integer

li $v0,5    
syscall #stores first int in $v0

add $s0,$v0, $zero
la $a0,prompt2  
li $v0,4    
syscall #puts first int into $t0, asks for second int.

li $v0,5    
syscall  #stores second int in $v0

move $s1,$v0  #moves second int into $t1
move $a0, $s0 #moves first int into $a0
move $a1, $s1 #moves second int into $a1
jal add #jumps to add method
move $t2, $v0 #moves the result of add method into $t2

la $a0,ans1 
li $v0,4
syscall # print string before result

move $a0,$t2    
li $v0,1    
syscall # print  result of sum

la $a0,endl 
li $v0,4    
syscall #prints blank line
#--------------------------------------------SUB
move $a0, $s0 #moves first int into $a0
move $a1, $s1 #moves second int into $a1
jal sub #jumps to sub method
move $t0, $v0 #Moves answer from sub method to $t0


la $a0,ans2 
li $v0,4
syscall # print string before result
move $a0, $t0 #moves answer from sub method $t0 into $a0 to be printed.
li $v0, 1 
syscall#prints result of difference

la $a0,endl 
li $v0,4    
syscall #prints blank line
#------------------------------------------mult
la $a0,ans3
li $v0,4
syscall # print string before result

move $a0, $s0 #moves first int into $a0
move $a1, $s1 #moves second int into $a1
jal mult
move $t0, $v0 #moves answer into $a0

move $a0, $t0 #moves answer from sub method $t0 into $a0 to be printed.
li $v0, 1 
syscall#prints result of difference

la $a0,endl 
li $v0,4    
syscall #prints blank line
#------------------------------------------
li $v0,10
syscall #ENDS PROGRAM
add:
move $t0, $a0
move $t1, $a1
add $v0, $t0, $t1
jr $ra #jumps back

sub:
move $t0, $a0
move $t1, $a1
sub $v0, $t0, $t1
jr $ra # jumps back

mult:
move $t0, $a0
move $t1, $a1
mult $t0, $t1 #multiplies $t0,$t1
mfhi $a0 #overflow
mflo $v0 #answer

.text       
main:
la $a0,prompt1  
li $v0,4
syscall #Asks for first integer

li $v0,5    
syscall #stores first int in $v0

add $s0,$v0, $zero
la $a0,prompt2  
li $v0,4    
syscall #puts first int into $t0, asks for second int.

li $v0,5    
syscall  #stores second int in $v0

move $s1,$v0  #moves second int into $t1
move $a0, $s0 #moves first int into $a0
move $a1, $s1 #moves second int into $a1
jal add #jumps to add method
move $t2, $v0 #moves the result of add method into $t2

la $a0,ans1 
li $v0,4
syscall # print string before result

move $a0,$t2    
li $v0,1    
syscall # print  result of sum

la $a0,endl 
li $v0,4    
syscall #prints blank line
#--------------------------------------------SUB
move $a0, $s0 #moves first int into $a0
move $a1, $s1 #moves second int into $a1
jal sub #jumps to sub method
move $t0, $v0 #Moves answer from sub method to $t0


la $a0,ans2 
li $v0,4
syscall # print string before result
move $a0, $t0 #moves answer from sub method $t0 into $a0 to be printed.
li $v0, 1 
syscall#prints result of difference

la $a0,endl 
li $v0,4    
syscall #prints blank line
#------------------------------------------mult
la $a0,ans3
li $v0,4
syscall # print string before result

move $a0, $s0 #moves first int into $a0
move $a1, $s1 #moves second int into $a1
jal mult
move $t0, $v0 #moves answer into $a0

move $a0, $t0 #moves answer from sub method $t0 into $a0 to be printed.
li $v0, 1 
syscall#prints result of difference

la $a0,endl 
li $v0,4    
syscall #prints blank line
#------------------------------------------
li $v0,10
syscall #ENDS PROGRAM
add:
move $t0, $a0
move $t1, $a1
add $v0, $t0, $t1
jr $ra #jumps back

sub:
move $t0, $a0
move $t1, $a1
sub $v0, $t0, $t1
jr $ra # jumps back

mult:
move $t0, $a0
move $t1, $a1
mult $t0, $t1 #multiplies $t0,$t1
mfhi $a0 #overflow
mflo $v0 #answer

li $v0,10
syscall 

.data

prompt1:.asciiz "Enter the first integer: "

prompt2:.asciiz "Enter the second integer: "

ans1:   .asciiz "The sum is "
ans2: .asciiz "The difference is "
ans3: .asciiz "The product is "
ans4: .asciiz "The quotient is "
endl:.asciiz "\n"

.data

prompt1:.asciiz "Enter the first integer: "

prompt2:.asciiz "Enter the second integer: "

ans1:   .asciiz "The sum is "
ans2: .asciiz "The difference is "
ans3: .asciiz "The product is "
ans4: .asciiz "The quotient is "
endl:.asciiz "\n"

1 个答案:

答案 0 :(得分:0)

我添加了


li $ v0,10#10是要退出的系统调用 系统调用


这为我解决了“自下而上”错误