看起来很简单,但我认为我的程序无法编译,因为我覆盖了 $v0 寄存器?提前致谢
更新:没关系,当我进行系统调用来打印总和时,我的订单是错误的...... 已修复,以防有人需要引用。
.data
prompt1: .asciiz "\n\n Enter the first integer please:"
prompt2: .asciiz "Enter the second integer please:"
result: .asciiz "The result is:"
.text
main:
#t0-to hold first integer
#t1-to hold second integer
#t2- used to hold the sum of t$1 and t$2
#first number
li $v0, 4 #syscall to print string
la $a0, prompt1 #address of string to print
syscall
li $v0, 5 #syscall to read an integer
syscall
move $t0, $v0 #move the number to read into $t0
#second number
li $v0, 4
la $a0, prompt2
syscall
li $v0,5
syscall
move $t1,$v0
add $t2, $t1, $t0 #compute the sum
#print out sum of $t2
li $v0, 4 # load syscall print int into $v0
move $a0, $t2 #move the number to print into $a0
li, $v0,1
la, $a0, result
syscall
Done:
li $v0, 10 #syscall to exit
syscall
最佳答案
.data
prompt1: .asciiz "\n\n Enter the first integer please:"
prompt2: .asciiz "Enter the second integer please:"
result: .asciiz "The result is:"
.text
main:
#t0-to hold first integer
#t1-to hold second integer
#t2- used to hold the sum of t$1 and t$2
#first number
li $v0, 4 #syscall to print string
la $a0, prompt1 #address of string to print
syscall
#
li $v0, 5 #syscall to read an integer
syscall
move $t0, $v0 #move the number to read into $t0
#second number
li $v0, 4
la $a0, prompt2
syscall
#
li $v0,5
syscall
move $t1,$v0
#
#print out sum of $t2
li $v0, 4
la $a0, result
syscall
#
add $a0, $t1, $t0 #compute the sum
li $v0, 1
syscall
#
li $v0, 10
syscall
关于assembly - Mips:计算两个输入的总和,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13576801/