I soon discovered that programs do ugly things to the stack, and having such a lovely custom menu arrangement I though I'd like to make programs that operate like function *only* change the X register and programs that act like procedures push their result onto the stack. So I built an external stack. These programs will work even one program calls another ( as a lot of mine do ) since the external stack can hold many previous incarnations of the stack contents.
BTW - I am *very* new to HP42 style programming so be gentle with me. I am just trying to find ways to leverage the most out of this truly incredible machine
Read on ..
Stack is initialiased ( once ) like so:
Code: Select all
SIZE 100
99
STO "SP"
The stack starts at register 99 and grows downwards. SP is the stack pointer.
There are two top level progams "STKPSH" which pushes the X,Y,Z and T registers onto the stack, leaving the current stack undisturbed. And "STKPOP" which pops the previously pushed values for X,Y,Z and T.
Code: Select all
LBL "STKPSH"
XEQ "STKSAV"
XEQ "PUSH"
XEQ "PUSH"
XEQ "PUSH"
XEQ "PUSH"
XEQ "STKRES"
END
LBL "STKPOP"
XEQ "POP"
STO "STK_T"
XEQ "POP"
STO "STK_Z"
XEQ "POP"
STO "STK_Y"
XEQ "POP"
STO "STK_X"
XEQ "STKRES"
END
LBL "STKRES"
RCL "STK_T"
RCL "STK_Z"
RCL "STK_Y"
RCL "STK_X"
END
LBL "STKSAV"
STO "STK_X"
R↓
STO "STK_Y"
R↓
STO "STK_Z"
R↓
STO "STK_T"
R↓
END
LBL "PUSH"
STO IND "SP"
R↓
1
STO- "SP"
R↓
END
LBL "POP"
1
STO+ "SP"
RCL IND "SP"
END
Code: Select all
XEQ "STKPSH"
... does something to X
STO "SAV_X"
XEQ "STKPOP"
R↓
RCL "SAV_X"
END
Code: Select all
XEQ "STKPSH"
... computes a new X
STO "SAV_X"
XEQ "STKPOP"
RCL "SAV_X"
END
Code: Select all
LBL "LYtoM"
XEQ "STKPSH"
RCL "C"
3600
×
24
×
365.25
×
×
STO "SAV_X"
XEQ "STKPOP"
R↓
RCL "SAV_X"
END