Local Flags

Post here to share useful tips and tricks, to ask questions about using your DM42 or to report software-related problems
Post Reply
whuyse
Posts: 198
Joined: Thu Dec 21, 2017 1:23 pm

Local Flags

Post by whuyse »

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: Select all

00 { 40-Byte Prgm }
01▸LBL "X<>F"
02 256
03 ÷
04 -7
05 X<>Y
06 IP
07▸LBL 02
08 STO+ ST X
09 FS?C IND ST Y
10 ISG ST X
11 LBL 00
12 LASTX
13 STO+ ST X
14 IP
15 STO- ST L
16 X>0?
17 SF IND ST Z
18 R↓
19 ISG ST Y
20 GTO 02
21 END
Hope you like it,
Werner
41CV†,42S,48GX,49G,DM42,DM41X,17BII,15CE, DM15L
Post Reply