The Museum of HP Calculators

HP Forum Archive 17

[ Return to Index | Top of Index ]

Programming "AND" of two flags in the non RPL machines
Message #1 Posted by Peter Niessen on 22 Aug 2007, 11:06 p.m.

Hi,

how to program an "AND" of two flags? I can come up only with

0
FS? 0
1
FS? 1
1
*
X!=0?

Is there a better way?

Thanks, Peter.

      
Re: Programming "AND" of two flags in the non RPL machines
Message #2 Posted by Paul Dale on 22 Aug 2007, 11:11 p.m.,
in response to message #1 by Peter Niessen

Slightly smaller is:

PI
FS? 0
IP        ; Integer part
FS? 1
FP        ; Fractional part
x=0?

- Pauli

      
Re: Programming "AND" of two flags in the non RPL machines
Message #3 Posted by Valentin Albillo on 23 Aug 2007, 8:59 a.m.,
in response to message #1 by Peter Niessen

Hi, Peter:

Peter asked:

    "How to program an "AND" of two flags? I can come up only with [... (a 7-step solution) ...] Is there a better way?

      If your program is intended to run in an HP-41C/CV/CX, an HP42S, or some suitably compatible model or emulation, and you don't care for the status of flag 00 (or 01) after the test, I can come up with a 3-step solution, namely:
          FC? 01
          CF  00
          FS? 00
      

      You can exchange flag 00 for flag 01 in the above solution if you can't afford clearing flag 00 but don't mind clearing flag 01 instead.

      Also, not only is my solution shorter, but significantly faster as well and the cherry on top is that it also preserves the whole RPN stack, LASTX included.

Best regards from V.

Edited: 23 Aug 2007, 9:10 a.m. after one or more responses were posted

            
Re: Programming "AND" of two flags in the non RPL machines
Message #4 Posted by Vincze on 23 Aug 2007, 9:05 a.m.,
in response to message #3 by Valentin Albillo

I guess I not understand something. What is flag checking?

                  
Re: Programming "AND" of two flags in the non RPL machines
Message #5 Posted by Giancarlo (Italy) on 23 Aug 2007, 9:19 a.m.,
in response to message #4 by Vincze

Hi Vincze.
If you question arises from the "FC" or "CF" acronyms, then they stand for "Flag Clear" and "Clear Flag" respectively.
"Clearing" a flag basically means "unsetting" it (i.e., setting its value to "0");
"Setting" a flag, obviously, means the opposite ;-)

"Flag checking" is just the checking for the flag status (set/clear).
If you mean "what is this strange mess with flags?", then very synthetically: many functions and settings of HP calcs
(at least of the most recent and powerful ones) are customizable by means of those "flag settings", which "set" the "operational environment" of the calc itself.
Hope my humble explanation was not more confusing to you ;-)
Best regards. Giancarlo

Edited: 23 Aug 2007, 9:20 a.m.

                        
Re: Programming "AND" of two flags in the non RPL machines
Message #6 Posted by Vincze on 23 Aug 2007, 9:30 a.m.,
in response to message #5 by Giancarlo (Italy)

I guess I more interested in what is flag setting all about. I know of 15C, there is flag setting to enter complex mode. But on 35s, I not understand when book says flags 0 - 4 mean whatever you want them to mean. Is it like it store boolean value for later use?

                              
Re: Programming "AND" of two flags in the non RPL machines
Message #7 Posted by Stefan Vorkoetter on 23 Aug 2007, 9:49 a.m.,
in response to message #6 by Vincze

Exactly. Flags are just boolean values. On the 35s, flags 0-4 happen to have their state displayed in the annunciator area, which makes them useful to visually indicate some sort of status. Some flags are also used to control settings of the calculator, such as setting flag 10 to inhibit equation evaluation.

Stefan

            
Re: Programming "AND" of two flags in the non RPL machines
Message #8 Posted by Stefan Vorkoetter on 23 Aug 2007, 9:56 a.m.,
in response to message #3 by Valentin Albillo

Another solution that preserves the stack and LASTx uses a third flag. So if you're testing flags 0 and 1, the following will set flag 2 to the AND of flags 0 and 1, and then test the result:

SF 2
FC? 0
CF 2
FC? 1
CF 2
FS? 2

Likewise, the following does OR:

CF 2
FS? 0
SF 2
FS? 1
SF 2
FS? 2

Alternatively, if all you're interested in is branching somewhere if the AND is true, you could write:

FC? 0
GTO N
FC? 1
GTO N
LBL A
...stuff to do if flags 0 and 1 are set

LBL N ...stuff to do if one or both of flags 0 and 1 are not set

Stefan

            
Re: Programming "AND" of two flags in the non RPL machines
Message #9 Posted by Peter Niessen on 23 Aug 2007, 2:54 p.m.,
in response to message #3 by Valentin Albillo

Had one only FC? on the 3Xs machines... (where X=2,3,5).

Thanks for these answers! Learnt something for today and should go home.

Cheers, Peter.


[ Return to Index | Top of Index ]

Go back to the main exhibit hall