(Free42) tips & tricks: local flags
|
07-23-2020, 10:21 AM
(This post was last modified: 07-23-2020 10:24 AM by Werner.)
Post: #1
|
|||
|
|||
(Free42) tips & tricks: local flags
LSTO has given us local variables, but we do not have local flags.
We can use a local variable (say, "F") to store a flag, and at first glance, 0 for a clear flag and 1 for a set flag would seem logical. However, the values -1e99 and 1e99 (the exponents are not important as long as they are larger than 34) are more convenient, as then the testing of the 'flag' can be performed with DSE and ISG, which will not change the stored value, but will skip accordingly: Flag Clear? -> ISG "F" Flag Set? -> DSE "F" to Set the flag (without disturbing the stack): LSTO "F" CLX 1e99 X<> "F" to Clear the flag: LSTO "F" CLX -1e99 X<> "F" Bear in mind that you can turn these into subroutines, but you can't include the LSTO statement in the subroutine.. (actually, even -1e9 and 1e9 will do for the flag values.. you're not likely to test the flag a billion times.. ;-) In case you need multiple flags, you may resort to saving the state of flags 0-7, using them for your own purpose, and restoring them. For that, X<>F (as in the '41 X-Functions) may be used: Code: 00 { 40-Byte Prgm } Hope you like it, Werner 41CV†,42S,48GX,49G,DM42,DM41X,17BII,15CE,DM15L,12C,16CE |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)