Post Reply 
HP42S making value comparisons
07-13-2020, 08:39 PM
Post: #1
HP42S making value comparisons
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.
Find all posts by this user
Quote this message in a reply
07-13-2020, 10:57 PM
Post: #2
RE: HP42S making value comparisons
(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?

On a side note, how many different ways did HP use for their programming? It seems that every programmable calculator does it differently.

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.

  
All My Articles & other Materials here:  Valentin Albillo's HP Collection
 
Visit this user's website Find all posts by this user
Quote this message in a reply
07-14-2020, 08:19 AM (This post was last modified: 07-14-2020 08:26 AM by ijabbott.)
Post: #3
RE: HP42S making value comparisons
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.)

— Ian Abbott
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 2 Guest(s)