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: 39
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: 13
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.

hsilop
Posts: 28
Joined: Thu Mar 14, 2019 12:35 am
Location: Canberra, Australia

Re: PUSH/POP stack

Post by hsilop » Fri Mar 15, 2019 12:19 am

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.
DM42 SN: 03223

HP-25, HP-33C, HP-41CV, HP-46, HP-11C, HP-12C, HP-15C, HP-16C

Thomas Okken
Posts: 567
Joined: Tue May 02, 2017 3:48 pm
Location: New Jersey, USA
Contact:

Re: PUSH/POP stack

Post by Thomas Okken » Fri Mar 15, 2019 12:30 am

→ 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: 28
Joined: Thu Mar 14, 2019 12:35 am
Location: Canberra, Australia

Re: PUSH/POP stack

Post by hsilop » Fri Mar 15, 2019 4:46 am

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

HP-25, HP-33C, HP-41CV, HP-46, HP-11C, HP-12C, HP-15C, HP-16C

hsilop
Posts: 28
Joined: Thu Mar 14, 2019 12:35 am
Location: Canberra, Australia

Re: PUSH/POP stack

Post by hsilop » Fri Apr 05, 2019 7:28 am

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.
DM42 SN: 03223

HP-25, HP-33C, HP-41CV, HP-46, HP-11C, HP-12C, HP-15C, HP-16C

budmur
Posts: 43
Joined: Tue Apr 25, 2017 12:06 pm
Location: Eastern Tennessee, USA

Re: PUSH/POP stack

Post by budmur » Fri Apr 05, 2019 1:24 pm

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