【发布时间】:2016-06-04 05:22:51
【问题描述】:
我正在尝试使用 mips 程序集,但发现分支机制存在问题。在我的代码的这个“短”部分中,但是错误所在的位置(我认为)。不管我输入什么数字,我都会跳到func1。 有人能帮我吗? 谢谢!
代码:
.text
.globl main
main:
.data
param: .float 0
val_1: .float 1
val_2: .float 2
val_3: .float 3
texto: .asciiz "type 1 for func 1, 2 for func 2 and 3 for func 3: \n"
.text
la $a0, texto #print
li $v0, 4
syscall
li $v0, 6 #read
syscall
la $t0, ($v0) #from $v0 to $t0
beq $t0, 1, func1 #branch for func1
beq $t0, 2, func2 #branch for func2
beq $t0, 3, func3 #branch for func3
j end
【问题讨论】:
-
如果
syscall和$v0 == 6是read_float,你为什么期望($v0)设置为有效地址? -
这是做什么的:
la $t0, ($v0)? Why are you using syscall 6 (read_float) when the options are 1, 2, and 3 (which are all integers)? -
这正是错误所在。谢谢!