Reputation: 175
Alright, so I've started writing MIPS code to multiply two arrays. I wanted to put what I had so far into QtSpim to see if values would change as I was expecting them to.
However, when I try to load my file into QtSpim I am getting this error:
Target of jump differs in high-order 4 bits from instruction pc 0x400014
Do you see where I'm going wrong, or have any good ideas for debugging? I'm not sure what or where the problem is.
Thanks.
EDIT: This works:
main:
la $a2, array1
la $a3, array2
li $a1, 5
li $v0, 1
add $a0, $a1, $0
syscall
lw $a0, 0($a2)
syscall
lw $a0, 0($a3)
syscall
li $v0, 10
syscall
.data
array1: .word 10, 10, 10, 10, 5
array2: .word -10, -10, 10, 10, 5
Full code:
.data
array1: .word 10, 10, 10, 10, 5
array2: .word -10, -10, 10, 10, 5
main:
li $a2, 5
addiu $15, $a2, 1
la $a0, array1
la $a1, array2
j MAC
MAC:
addiu $sp, $sp, -4
sw $ra, 4($sp)
li $v1, 0
li $s0, 0
loopInMAC:
beq $s0, $15, main2
j mult1
add $v1, $v1, $v0
addiu $s0, $s0, 1
j loopInMAC
mult1:
lw $s1, 0($a0)
lw $s2, 0($a1)
slt $s3, $s1, 0
slt $s4, $s2, 0
addiu $sp, $sp, -4
sw $ra 0($sp)
bne $s3, 1, skip1
sub $s1, $0, $s1
skip1:
bne $s4, 1, skip2
sub $s2, $0, $s2
skip2:
li $v0, 0
loopInMult:
beq $s1, $0, skip3
andi $t0, $s1, 1
beq $t0, $0, skipAdd
add $v0, $v0, $s2
skipAdd:
sll $s2, $s2, 1
srl $s1, $s1, 1
j loopInMult
skip3:
beq $s1, $s2, equalSign
sub $v0, $0, $v0
equalSign:
jr $ra
Upvotes: 1
Views: 8271
Reputation: 58427
Don't place code in the .data
section. You should start the .text
(code) section before main:
, i.e:
.text
main:
Also, you've got a couple of instructions placed before main:
that currently will never be executed. I suspect that those are meant to be placed after main:
Upvotes: 5