C.E.Sally
C.E.Sally

Reputation: 381

When calling into C from MIPS do we use JR or JALR?

I'm writing some self-modifying code and I want to call a C function (call it foo) from MIPS.

I've loaded the mem add of foo, &foo into $t1. Now I jr/jalr $t1.

Will C set $ra as my current PC(+8) (before the jump) allowing me to use JR or will I have to JALR instead (ie, take care of it because C won't)?

I can't test this right now as I'm debugging my macros (for the MIPS mnemonics). I must have messed some up because I keep getting illegal instruction errors.

Upvotes: 0

Views: 951

Answers (1)

zwol
zwol

Reputation: 140786

You have to use JALR. How could the C function possibly know how to set $ra for you?

Upvotes: 1

Related Questions