PUSH/POP stack

Contributions to this software library are always welcome. Please ensure that you post program listings rather than .raw files. They give a reasonable idea of what your program does without having to load them into a DM42 and you can also include comments in your code. Check out the following link for a decoder/encoder: http://www.swissmicros.com/dm42/decoder/

You can then copy/paste the listing and post it in "code" tags.
Post Reply
whuyse
Posts: 22
Joined: Thu Dec 21, 2017 12:23 pm

PUSH/POP stack

Post by whuyse » Thu Dec 21, 2017 12:41 pm

As requested in another topic.
Before first use, create a 1x4 matrix and call it "STACK".
Of course, the stack may not hold complex numbers or matrices.

Code: Select all

00 { 74-Byte Prgm }
01>LBL "PUSHST"
02 INDEX "STACK"
03 INSR
04 R^
05 STOEL
06 J+
07 R^
08 STOEL
09 J+
10 R^
11 STOEL
12 J+
13 R^
14 STOEL
15 EXITALL
16 RTN
17>LBL "POPST"
18 INDEX "STACK"
19 STO ST L
20 RCLEL
21 ENTER
22 ->
23 ENTER
24 ->
25 ENTER
26 ->
27 DELR
28 EXITALL
29 X<> ST L
30 END
POPST will put back the original LXYZT as XNYZT, with N the X-register content before calling POPST; consistent with the way a 1-argument function works. To restore the stack mimicking a 2-argument function (thus returning XNZTT) use

Code: Select all

>LBL "POP2ST"
 INDEX "STACK"
 STO ST L
 RCLEL
 ENTER
 ENTER
 ->
 J+
 ENTER
 ->
 DELR
 EXITALL
 X<> ST L
 RTN
Cheers, Werner
42S #3249S01123
DM42 #00345

tcab
Posts: 12
Joined: Sun Jan 14, 2018 11:03 am

Re: PUSH/POP stack

Post by tcab » Sat Feb 03, 2018 9:34 pm

Nice algorithm- thanks.
In the first version, modifying it slightly to leave out line 29 will restore XYZT as it was, which I prefer. Then if I happen to want what was in X prior to calling POPST, I can do a LASTX.

Post Reply