35s: Using STO in EQN in RPN program Message #1 Posted by Matt Draper on 4 Oct 2008, 2:33 p.m.
I've always enjoyed reading this forum. Thank you all for the priceless exchange of ideas and information, and for the good company these past few years.
I got my 35s a week ago, and I've really been enjoying it. Looking through the archives I was surprised to learn that STO can be used in an equation, since the Operation Index in the User's Guide does not indicate that this function can be used in an equation. Coming from the 11C and 42S, this whole business of using equations in an RPN program is very new and interesting to me, and learning that it's possible to use STO in an equation is even more of an eyebrowraiser. I was also excited to read about using an equation in a program to emulate the stackpreserving behavior of builtin functions.
After spending a few days putting together useful programs for my everyday calculations, I decided it might be fun to tinker with equations in an RPN program. I wondered if it was possible to write a single equation that stores the contents of the stack registers into a series of indirect variables. Arne wrote a straight RPN routine that does a nice job at this, but I wanted to see if I could do it in an equation. This is what I came up with:
A001 LBL A
A002 5>I>(I)1>I*0+LASTx>(I)*0>I+REGX>(I)*0+1>I*0+REGY>(I)*0+2>I*0+REGZ>(I)*0+3>I*0+REGT>(I)
A003 Rv
A004 RTN
Where ">" is STO, and "" is the minus operator, not CHS.
I know it looks weird, but it actually works. The first part of the equation, "5>I>(I)", stores a nonzero value (5) in variable 005 to ensure adequate memory allocation for the registers in the event that variable 004 ends up holding a zero value. The rest of it stores REGX, REGY, REGZ, REGT, and LASTx into variables 000, 001, 002, 003, and 004, respectively.
The equation ultimately evaluates to the initial value of REGT, which it dutifully pushes onto the stack. Aside from pushing REGT, it doesn't mess with the stack or LASTx at all, so following it up with a RollDown leaves the stack and LASTx in their initial state.
Any ideas for simplifying or speeding up the equation?
I'm presenting this more as a curiosity than something you might want to actually use, since it's much faster, not to mention easier to read, to do it the straight RPN way. Besides, it might make your screen tilt if you use it too much ;)
