0
我想實現一個MIPS計算器,它需要3個整數作爲輸入並返回一個輸出。目前,代碼輸出「int1,int2和int3的總和爲1」,我不明白爲什麼。也許我沒有正確寫入加法子程序?MIPS計算器不能正常輸出
.data
welc: .asciiz "Enter an integer:\n"
sum: .asciiz "The sum of "
prod: .asciiz "The product of "
divi: .asciiz "The quotient of "
subt: .asciiz "The difference of "
also: .asciiz " and "
comma: .asciiz ", "
rem: .asciiz "remainder:"
is: .asciiz " is "
int1: .word 1 #space to hold first int
int2: .word 1 #space to hold second int
int3: .word 1 #space to hold third int
input: .space 1 #space to hold raw input
out: .word 1 #space to hold output
remain: .word 1 #space to hold remainder
.text
.globl main
main : li $v0, 4 #syscall 4, print string
la $a0, welc #give argument: string "Enter an integer:"
syscall
li $v0, 5 #tell syscall we want to read int 1
syscall
la $s1, int1 #load int1 into $s1
sw $v0, 0($s1) #copy int from $v0 to int 1
li $v0, 4 #syscall 4, print string
la $a0, welc #give argument: string "Enter an integer:"
syscall
li $v0, 5 #tell syscall we want to read int 2
syscall
la $s2, int2 #load int2 into $s2
sw $v0, 0($s2) #copy int from $v0 to int 2
li $v0, 4 #syscall 4, print string
la $a0, welc #give argument: string "Enter an integer:"
syscall
li $v0, 5 #tell syscall we want to read int 3
syscall
la $s3, int3 #load int3 into $s3
sw $v0, 0($s3) #copy int from $v0 to int 3
la $s0, out #load output to $s0
j plus #jump to calc
plus: add $s0, $s1, $s2 #add int1 and int2 and put in out
add $s0, $s0, $s3 #add out and int3
li $v0, 4 #tell syscall to print string
la,$a0, sum #print sum string
syscall
li $v0, 1 #tell syscall to print int
la $s1, int1 #tell syscall to print int1
lw $a0, 0($s1) #load int 1 into $a0 and print
syscall
li $v0, 4 #tell syscall to print string
la,$a0, comma #tell syscall to print comma
syscall
li $v0, 1 #tell syscall to print int
la $s2, int2 #tell syscall to print int2
lw $a0, 0($s2) #load int 2 into $a0 and print
syscall
li $v0, 4 #tell syscall to print string
la,$a0, comma #tell syscall to print comma
syscall
li $v0, 4 #tell syscall to print string
la,$a0, also #tell syscall to print comma
syscall
li $v0, 1 #tell syscall to print int
la $s3, int3 #tell syscall to print int3
lw $a0, 0($s3) #load int 3 into $a0 and print
syscall
li $v0, 4 #tell syscall to print string
la,$a0, is #tell syscall to print is
syscall
li $v0, 1 #tell syscall to print int
la $s0, out #tell syscall to print output
lw $a0, 0($s0)
syscall
li $v0, 10 #exit code
syscall