当我等待减法的结果出现时出现问题,但它显示我0.不是x-a,正如我希望的那样。
.data
strin: .asciiz "type two integers\n\n\n"
strout: .asciiz "the result of the substract is:"
a: .word 0
x: .word 1
.text
main:
li $v0, 4
la $a0,strin
syscall
li $v0, 5
syscall
sw $t0,a
li $v1,5
syscall
sw $t1,x
sub $t1,$t1,$t0
li $v0, 4
la $a0,strout
syscall
move $a0, $t1
li $v0, 1
syscall
li $v0,10
syscall
答案 0 :(得分:1)
更好的方法是将整数作为输入读取,然后进行计算。 将值存储在内存中然后将其读取为不是一种实用的方法 如果您不想将数字作为输入读取,我建议您使用li指令将特定数值加载到寄存器中,然后继续进行计算。
.data
strin: .asciiz "type two integers\n"
strout: .asciiz "the result of the substract is:"
.text
.globl main
main:
li $v0, 4
la $a0,strin
syscall
#changed
li $v0, 5 #Read the first integer
syscall
move $t0,$v0 #move the value you read to $t0 register
#changed
li $v0, 5 #Read the second integer
syscall
move $t1,$v0 #move the value you read to $t1 register
sub $s0,$t0,$t1 #make substraction between $t0 and $t1 and store the
#result in $s0 register
li $v0, 4
la $a0,strout
syscall
li $v0, 1
move $a0, $s0
syscall
li $v0,10
syscall