Saturday, September 22, 2007

Saving HP-35s' stack in indirect registers

NOTE: Program here has bugs and is no longer maintained, use program listed here.

The method of imitating native operations stack and lastx behaviour used here and here is perfect for cases when job can be done with a single equation. For longer and more traditional rpn type of programs one may want to save the stack.

The following program stores X stack register content in register 0, Y stack register in 1, Z stack register in 2 and T stack register in 3.

U001 LBL U
U002 X<> I
U003 RDN
U004 0
U005 X<> I
U006 STO(I)
U007 RDN
U008 1
U009 STO I
U010 RDN
U011 STO(I)
U012 RDN
U013 2
U014 STO I
U015 RDN
U016 STO(I)
U017 RDN
U018 3
U019 STO I
U020 RDN
U021 STO(I)
U022 3
U023 STO I
U024 RDN
U025 RCL(I)
U026 2
U027 STO I
U028 RDN
U029 RCL(I)
U030 1
U031 STO I
U032 RDN
U033 RCL(I)
U034 0
U035 STO I
U036 RDN
U037 RCL(I)
U038 RTN

Terms of use.

The start is a bit tricky since we are storing in indirect registers (do not want to use high valuable variable registers for this) and need to enter index 0 in I but stack is full of stuff not to be lost. Rescue operator is X<> I: Swaps content in I with X, get old I content to T and put index O in X, swap it with old X content which then is stored in register 0. From then on it is straight forward.

This program restore the stack after it is saved (program calling propably would like that...), that is what lines 22-38 does. Note that when 22-38 execute in context of last part of saving the stack there are some redundant lines, but wrote it like this so XEQ U022 can be used in general to recall saved stack.

NOTE: I made a modification and an extension to this program.

No comments: