• Welcome to Final Fantasy Hacktics. Please login or sign up.
 

Return location in the wiki

Started by Orkney, January 15, 2021, 03:08:32 pm

Orkney

Hi !

I'm a bit lost,

I started to complete the wiki while I was consulting its pages. Not very complicated things, putting links and filling in return locations.

I've just noticed that there are several ways of doing things (which may not be a good thing).
Sometimes it is the first line of the formula/routine that is indicated, sometimes it is the exact line of the return that is indicated .

I can understand both ways, but I can't say which one is more appropriate... Is there a place where the writing rules are detailed or do we just have to rely on common sense?

  • Modding version: PSX

nitwit

I'm sure there's a convention, but you could avoid having to deal with it by renaming "return locations" to "called from locations".

IIRC, a jal executes the next line of code, then jumps to wherever it's going. So the return location should be the 2nd line after the jal.

jal
whatever, executed before the jump
whatever, return location

I would verify that first though

https://chortle.ccsu.edu/AssemblyTutorial/Chapter-26/ass26_4.html
^Seems like it's the 2nd location after the jal.
QuoteVery Tricky: the middle step of the machine cycle has already incremented the PC by four. At this point the PC holds the address of the instruction just after the jal instruction. Now the execute phase of the jal instruction adds four to that address and puts the result in $ra. So now $ra holds the address of the second instruction after the jal instruction.

The correct return address is "address of the jal plus eight". This is because: (i) returning from the subroutine to the jal instruction would be a disaster (since it would execute again, sending control back to the subroutine), and (ii) the instruction following the jal is a branch delay slot.