0

I have the following mips code:

.text
c:
    li $8, 0
    addu $sp, $sp, -4
    sw $8, 0($sp)
    jr $ra
a:
    li $8, 0
    addu $sp, $sp, -4
    sw $8, 0($sp)
    addu $sp, $sp, -4
    sw $8, 0($sp)
    addu $sp, $sp, -8
    sw $fp, 0($sp)
    sw $ra, 4($sp)
    jal c
    lw $fp, 0($sp)
    lw $ra, 4($sp)
    addu $sp, $sp, 8
    lw $8, 0($sp)
    addu $sp, $sp, 4
    jr $ra
main:
    addu $sp, $sp, 0
    addu $sp, $sp, -8
    sw $fp, 0($sp)
    sw $ra, 4($sp)
    jal a
    lw $fp, 0($sp)
    lw $ra, 4($sp)
    addu $sp, $sp, 8
    addu $sp, $sp, 0
    j exit

I get " Exception 6 [Bad instruction address]", but I can't see anything wrong with the code.

How can I know where is it happening? I run the code using spim command. I suspect the return adress or the stack pointer is not being restored' but it looks right to me, what am I doing wrong?

New contributor
SuzLy is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
  • Your question is off topic here and so not suited to this site. See me or one of my colleagues at Codementor.io, and I can help you debug/work through this. If you're running the MARS simulator, it will start out running the code immediately after the .text directive: you could rearrange it so that the main code comes first after .text, instead of c (or a) -- (or else put a j main at the beginning after .text and before c:). – Erik Eidt 3 hours ago

Your Answer

SuzLy is a new contributor. Be nice, and check out our Code of Conduct.

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.