Assembly MIPS jal指令:跳转目标与指令pc 0x400014的高阶4位不同
我知道我一定是在某个地方跳得太大了,但我真的不知道问题出在哪里。我怀疑我在代码中使用了太多的寄存器。但是程序规范说某些值必须存储在$s0、$s1和s2中。我还必须使用参数寄存器和结果寄存器。使用的唯一温度寄存器是t0和t1 伪代码:Assembly MIPS jal指令:跳转目标与指令pc 0x400014的高阶4位不同,assembly,mips,Assembly,Mips,我知道我一定是在某个地方跳得太大了,但我真的不知道问题出在哪里。我怀疑我在代码中使用了太多的寄存器。但是程序规范说某些值必须存储在$s0、$s1和s2中。我还必须使用参数寄存器和结果寄存器。使用的唯一温度寄存器是t0和t1 伪代码: Main: int z = 37; input x; input y; sum = procedure1(x,y); output x, y, sum; int procedure1 (int a, int b) a = a-b; output a; total
Main:
int z = 37;
input x;
input y;
sum = procedure1(x,y);
output x, y, sum;
int procedure1 (int a, int b)
a = a-b;
output a;
total = a+3b;
return total;
以下是我的完整代码:
.data
zVar: .word 37
outputnewline: .asciiz "\n"
getInput: .asciiz "Enter an integer"
outproc1: .asciiz "procedure 1: "
outmain: .asciiz "Main: "
space: .asciiz " "
main:
li $v0, 4 #prompt for x
la $a0, getInput
syscall
li $v0, 5 #read in x
syscall
move $s0, $v0 #store x in $s0
move $a0, $v0 #pass x using $a0
li $v0, 4 #start a new line
la $a0, outputnewline
syscall
li $v0, 4 #prompt for y
la $a0, getInput
syscall
li $v0, 5 #read in y
syscall
move $s1, $v0 #store y in $s1
move $a1, $v0 #pass y using $a1
jal procedure1
move $s2, $v0 #store sum in $s2
li $v0, 4 #print out "Main: "
la $a0, outmain
syscall
li $v0, 1 #print out x
move $a0, $s0
syscall
li $v0, 4 #print out " "
la $a0, space
syscall
li $v0, 1 #print out y
move $a0, $s1
syscall
li $v0, 4 #print out " "
la $a0, space
syscall
li $v0, 1
move $a0, $s2
syscall
li $v0, 4 #start a new line
la $a0, outputnewline
syscall
li $v0, 10
syscall #exits the program
procedure1:
sub $t0, $a0, $a1 #a=a-b, store a in $t0
addi $sp, $sp, -12
sw $a0, 0($sp) #put a on stack
sw $a1, 4($sp) #put b on stack
sw $s0, 8($sp) #put $s0 on stack
li $v0, 4 #print out "procdure 1: "
la $a0, outproc1
syscall
li $v0, 1 #print out a
move $a0, $t0
syscall
li $v0, 4 #start a new line
la $a0, outputnewline
syscall
lw $a0, 0($sp) #restore a
lw $a1, 4($sp) #restore b
add $t1, $zero, 3 #operand 3
mult $a1, $t1 # 3*b
mflo $s0 #store 3b in $s0
add $s0, $s0, $a0 #store a+3b in $s0
move $v0, $s0 #store total in $v0
lw $s0, 8($sp)
addi $sp, $sp, 8
jr $ra
不要将代码放在.data部分。将初始化的数据放在.data中,将代码放在.text中如果@Michael的评论不能解决您的问题,您可以使用la$reg函数;jalr$reg调用32位地址空间中任意位置的函数。这解决了问题。从现在起,我将确保将代码放入.text部分。谢谢你的留言!