WiiRd forum

Wii & Gamecube Hacking => Wii Game hacking help => Topic started by: biolizard89 on October 26, 2012, 06:30:26 AM

Title: Do the compare registers persist through stack frames?
Post by: biolizard89 on October 26, 2012, 06:30:26 AM
Let's say I save a stack frame, do some stuff with registers, do a cmp opcode, restore the stack frame, and then use beq.  Will the beq outside of the stack frame be able to see the compare registers from inside the stack frame, or does restoring the stack frame wipe that?

Thanks.
Title: Re: Do the compare registers persist through stack frames?
Post by: megazig on October 26, 2012, 06:33:29 AM
yes, the condition reg isn't stack dependant. it will last until another instruction sets something there
Title: Re: Do the compare registers persist through stack frames?
Post by: biolizard89 on October 26, 2012, 06:38:37 AM
Quote from: megazig on October 26, 2012, 06:33:29 AM
yes, the condition reg isn't stack dependant. it will last until another instruction sets something there
Awesome, thanks megazig.  This greatly simplifies the thing I'm coding at the moment....  :)
Title: Re: Do the compare registers persist through stack frames?
Post by: dcx2 on October 30, 2012, 01:11:32 AM
This may come in handy.  http://wiird.l0nk.org/forum/index.php/topic,8768.msg75642.html#msg75642

Condition Register fields 2, 3, and 4 are non-volatile.  So if you use cr2, cr3, or cr4, you do actually have to push and pop the CR.

CR 0, 1, 5, 6, 7 are volatile, so feel free to use them without saving them.  I would prefer cr5, 6, or 7 because game code is less likely to use those ones.

However, assuming that you didn't push CR onto the stack when you created your stack frame, then you won't be popping it either, so the contents will be unchanged.  Popping a stack frame always involves directly lwz'ing the register in question so there is never ambiguity about what registers were changed, except for lmw.