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: https://technical.swissmicros.com/decoders/dm42/

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

PUSH/POP stack

Post by whuyse »

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
41CV†,42S,48GX,49G,DM42,DM41X,17BII,15CE, DM15L
tcab
Posts: 13
Joined: Sun Jan 14, 2018 12:03 pm

Re: PUSH/POP stack

Post by tcab »

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.
hsilop
Posts: 70
Joined: Thu Mar 14, 2019 1:35 am
Location: Canberra, Australia

Re: PUSH/POP stack

Post by hsilop »

This looks brilliant!

I am trying to understand what you are doing here, but what instruction/key does the symbol

->

refer to ?

Thanks. I did a similar think using indirect addressing but I think a matrix would work better and not conflict with other memory hungry apps such as statistical operations.
Steve

DM32 SN: 00316
DM41X SN: 00854
DM42 SN: 03223


HP11C, HP12C, HP15C, HP16C, HP25, HP32S, HP33C, HP41CV, HP46, HP65
Thomas Okken
Posts: 1100
Joined: Tue May 02, 2017 5:48 pm
Location: Netherlands
Contact:

Re: PUSH/POP stack

Post by Thomas Okken »

→ is one of the matrix editor's cell movement commands. It stores the contents of the X register in the current cell, moves the cell pointer one to the right, and puts the contents of that next cell in X. It is roughly equivalent to STOEL J+ RCLEL.

If all that is Greek to you, I recommend reading the documentation. Specifically, go to http://thomasokken.com/free42/, scroll down to Documentation, and start from there. In the HP-42S manual, specifically check out chapter 14, Matrix Operations.
hsilop
Posts: 70
Joined: Thu Mar 14, 2019 1:35 am
Location: Canberra, Australia

Re: PUSH/POP stack

Post by hsilop »

Thanks dude. Don't worry, I'm a retired IT guy with a new DM42 and time to burn. I will work it out.
Steve

DM32 SN: 00316
DM41X SN: 00854
DM42 SN: 03223


HP11C, HP12C, HP15C, HP16C, HP25, HP32S, HP33C, HP41CV, HP46, HP65
hsilop
Posts: 70
Joined: Thu Mar 14, 2019 1:35 am
Location: Canberra, Australia

Re: PUSH/POP stack

Post by hsilop »

This is far superior to my "solution"!

Is there a way to test if "STACK" exists in the PUSH function? That way you could dynamically create it as needed. Just a thought. Matrices are cool in HP42S/DM42 land! Registers ... pfft.
Steve

DM32 SN: 00316
DM41X SN: 00854
DM42 SN: 03223


HP11C, HP12C, HP15C, HP16C, HP25, HP32S, HP33C, HP41CV, HP46, HP65
budmur
Posts: 46
Joined: Tue Apr 25, 2017 2:06 pm
Location: Eastern Tennessee, USA

Re: PUSH/POP stack

Post by budmur »

As I understand it, one disadvantage of this method is that the stack can't contain a matrix. The other way (using registers) would be able to support a matrix on the stack.
DM42 S/N 00039
Post Reply