我在尝试完成一个MIPS程序时遇到问题,该程序需要输入整数并打印出两个较大的整数。 我的代码:MIPS读取2个整数然后打印出较大的一个
#read 2 integer numbers and print out the larger one
.data # data section
mes1: .asciiz "\n\nEnter the first integer number: "
mes2: .asciiz "Enter the second integer number: "
mes3: .asciiz "The larger integer number is: "
.text # code section
li $v0, 4 #print a string "mes1"
la $a0, mes1
syscall
li $v0, 5 #read the first integer
syscall
move $t0, $v0
li $v0, 4 #print a string "mes2"
la $a0, mes2
syscall
li $v0, 5 #read the second integer
syscall
move $t1, $v0
addi $t0, $zero, -100 #Get larger integer (the first or the second)
addi $t1, $zero, -100
slt $s0, $t0, $t1
bne $s0, $zero, mes3
syscall
li $v0, 4 #print a string "mes3"
la $a0, mes3
syscall
li $v1, 1 #print the larger int number
move $a0, $v0
syscall
li $v0, 10 # system call for exit
syscall
请更详细地什么问题,你有解释,它在做什么,而不是它应该做的事等 –
但显然你正在做一些奇怪的算术(为什么加-100?),你会跳到一个字符串标签'mes3'而不是实际的代码标签等。 –
Mips使用带有'$ zero'的'addi'来加载立即数。实际上'-100'不会被添加到读取的数字中。但是我不清楚将$ t0和$ t1设置为-100的意义。这需要[mcve]。另外,包括你目前使用调试器的想法。 –