|[WP34s] Local variables|
Message #15 Posted by Marcus von Cube, Germany on 7 Nov 2011, 4:59 a.m.,
in response to message #14 by fhub
When the new features become usable and stable enough I will discuss them here. If you want to play around with them, here is a short guide:
- In a subroutine, issue LOCL nn where nn denotes the highest numbered local register you want to use. Newly created registers are zeroed.
- In the same or any nested subroutine you can now address the newly created registers with a dot in the name: .00 to .nn. For direct addressing, .nn is limited to .15 (these are restrictions in the internal coding of commands.) but indirect addresses may go higher, starting at 112 for .00.
- Another call to LOCL in the same subroutine just changes the size of the local register space. LOCL in any nested subroutine will establish a new frame which hides the local registers one level up.
- Use MEM? to find out about the number of levels left. Each frame needs 2 levels + 4 for every local register. The space is taken from the return stack which extends downwards into program space. If you need many local variables, run your program off flash memory and clear the program in RAM.
- Be aware that any action that clears the return stack will remove all local variables: Manual RTN, editing your program and some more keyboard actions. This is the reason why data that is input manually by a user is better held in the normal register space.
- Each frame establishes 16 local flags .00 to .15 in addition to the registers. They can be used like any other flag.
- Use RTN from the same subroutine that has issued LOCL to get rid of the most recently allocated frame and return to the caller. Use LPOP to just delete the variables without returning.
For examples, just look at xrom.wp34s.