Vlad
Vlad

Reputation: 8585

How to save program counter address without using J-Type instructions in MIPS architecture

I have to implement jal instruction as pseudo-instruction without using J-Type instructions. I can implement it with jr but I know that jal stores current PC+8 in $ra. How can I implement that? How can I store PC address in ra without J-type?

Upvotes: 3

Views: 1167

Answers (1)

markgz
markgz

Reputation: 6266

Try this:

    la  $ra, ret    # load return address (pseudo instruction!)
    j   dest        # call the function
    nop             # delay slot
ret:                # return here
    ...

dest:               # destination function
    ...
    jr  $ra

Upvotes: 1

Related Questions