我对MIPS很陌生,我正在做一个任务,要找到用户给定的2个数字之间的最大值,但是我遇到了两个错误,我不明白为什么,我写的代码从max开始:。谢谢你的帮助
错误1:第35行第9列:“$ra”:操作数的类型不正确
错误2:第40行第18列:“else”:操作数的类型不正确
.text
main:
li $sp, 0x7ffffffc # initialize $sp
# PROLOGUE
subu $sp, $sp, 8 # expand stack by 8 bytes
sw $ra, 8($sp) # push $ra (ret addr, 4 bytes)
sw $fp, 4($sp) # push $fp (4 bytes)
addu $fp, $sp, 8 # set $fp to saved $ra
li $v0, 5 # read x into a0
syscall
move $a0, $v0
li $v0, 5 # read y into a1
syscall
move $a1, $v0
# lw $a1, arg0 # a1 = arg1
# lw $a2, arg1
jal max # v0 = max(arg0, arg1)
move $a0, $v0 # print_int(rval)
li $v0, 1
syscall
li $v0, 11 # print_char(\n)
li $a0, 10
syscall
# EPILOGUE
move $sp, $fp # restore $sp
lw $ra, ($fp) # restore saved $ra
lw $fp, -4($sp) # restore saved $fp
j $ra # return to kernel
max:
#PROLOGUE
# $a0 = x, $a1 = y
sle $a0, $a1, else # if(x <= y), jump to else
move $t0, $a0 # if (x > y), x is max
else: move $t0, $a1 # set $t0 = $t2, y is max
1条答案
按热度按时间cig3rfwq1#
j $ra
必须为jr $ra
sle $a0, $a1, else
应为ble $a0, $a1, else
这应该可以修复两个汇编程序错误。