Post Reply 
Accessing / Manipulating RPN Stack from PPL
05-14-2018, 09:08 PM (This post was last modified: 05-15-2018 05:24 PM by Stevetuc.)
Post: #6
RE: Accessing / Manipulating RPN Stack from PPL
Here is a workaround to allow writing back to multiple stack locations from PPL
It uses the fact that a key definition returns a string to the command line without quotes. So RETURN "stack1 stack2 stack3 stack4" will place those vars onto the lowest 4 stack levels on pressing <ENTER>

In the code below , global vars are created to hold the stack values.
Ans(1) to Ans(4) are used to pop 4 values from the stack.
a sample routine then takes the factorial of the stack values.
on pressing SHIFT User 0, stack4 stack3 stack2 stack1 is placed on the command line, and <ENTER> pushes them onto stack.

try this:
Home screen RPN mode
place on stack:
2 <ENTER>
4 <ENTER>
6 <ENTER>
8 <ENTER>
Shift User 0
stack4 stack3 stack2 stack1 is returned
<ENTER>

2
24
720
40320
is returned to the stack

Code:

EXPORT stack1,stack2,stack3,stack4; //global stack vars
KEY K_0()
BEGIN
//pop 4 items from stack
Ans(1)▶stack1;Ans(2)▶stack2;Ans(3)▶stack3;Ans(4)▶stack4;

//routines go here
stack1!▶stack1; 
stack2!▶stack2; 
stack3!▶stack3;
stack4!▶stack4;

//push 4 items to stack. Detect Entry and return array if not RPN mode
RETURN  IFTE(Entry==2,"stack4 stack3 stack2 stack1","{stack4,stack3,stack2,stack1}");
END;
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Accessing / Manipulating RPN Stack from PPL - Stevetuc - 05-14-2018 09:08 PM



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