HP42S making value comparisons - Printable Version +- HP Forums ( https://www.hpmuseum.org/forum)+-- Forum: HP Calculators (and very old HP Computers) ( /forum-3.html)+--- Forum: General Forum ( /forum-4.html)+--- Thread: HP42S making value comparisons ( /thread-15341.html) |

HP42S making value comparisons - Davidy - 07-13-2020 08:39 PM
What's the easiest way to compare the x value with a constant during a running calculation without upsetting the stack? You can easily compare to y or to 0 but how about to a stored value? On a side note, how many different ways did HP use for their programming? It seems that every programmable calculator does it differently. RE: HP42S making value comparisons - Valentin Albillo - 07-13-2020 10:57 PM
(07-13-2020 08:39 PM)Davidy Wrote: What's the easiest way to compare the x value with a constant during a running calculation without upsetting the stack? You can easily compare to y or to 0 but how about to a stored value? I don't have a 42S at hand but something like this might work: Let's assume that the stored value is in R13 and if the value in the X stack register equals that value then execution should branch to LBL 07. To achieve what you want, do this: RCL- 13 X=0? GTO 07 X<> ST L This leaves the stack as it was before the comparison, except for the LastX register (ST L). If you don't need the value of X after the comparison, omit the X<> ST L step. If you need the value of X (and Y,Z,T) at the LBL 07 destination, put the X<> ST L there as well, like this: LBL 07 X<>ST L This won't work for alpha data, of course. V. RE: HP42S making value comparisons - ijabbott - 07-14-2020 08:19 AM
Something like this should work: X<> ST L Rv 42 ; arbitrary real constant RCL- ST L X=0? GTO "FOO" RCL- ST L +/- .... LBL "FOO" RCL- ST L +/- .... It uses LASTX for temporary storage like Valentin's solution, but allows the (real) constant to be entered literally. (It won't work for complex constants because you need two stack positions to enter a complex constant.) |