PUSH and POP stack routines

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.
User avatar
lispm
Posts: 27
Joined: Tue Jun 29, 2021 2:23 pm
Location: Germany

PUSH and POP stack routines

Post by lispm »

I felt the need to have an additional stack to store intermediate results during computation, that can store data of any type (float, complex numbers, strings, matrices an even lists). Luckily Thomas Okken introduced lists as a new data type in Free42 3.0.6.

The number of elements on the stack is only limited by the available memory.

The program works both in NSTK and 4STK mode.

Usage
  • XEQ "Push": Topmost element is removed from the stack and stored on the newstack, LASTX is preserved
  • XEQ "Pop": Toṕmost element is removed from the new stack and stored on the normal stack. If there is no element left on the stack the POP routine returns "NONEXISTENT" error 6.
  • XEQ "PushAll": The complete stack is saved on the newstack.
  • XEQ "PopAll": Every element on new stack is popped.
Changes

I replaced my original source code of PUSH with Thomas Okkens version because it is better than my first version. The POP routine has been changed not to return NO but the error NONEXISTENT if the stack is empty.

Source Code

Code: Select all

00 { 104-Byte Prgm }
01▸LBL "Push"
02 FUNC 10
03 NEWLIST
04 X<>Y
05 APPEND
06 SF 25
07 RCL "μ"
08 FS?C 25
09 EXTEND
10 STO "μ"
11 RTN
12▸LBL "PushAll"
13 LNSTK
14 DEPTH
15 LSTO "c"
16 DROP
17▸LBL 02
18 XEQ "Push"
19 DSE "c"
20 GTO 02
21 RTN
22▸LBL "Pop"
23 FUNC 01
24 SF 25
25 HEAD "μ"
26 RTN
27 RTNERR 6
28▸LBL "PopAll"
29 SF 25
30▸LBL 00
31 XEQ "Pop"
32 FS? 25
33 GTO 00
34 CF 25
35 END
Download

Here you can download the PUSHPOP.raw file.
Last edited by lispm on Sun Apr 03, 2022 6:55 pm, edited 7 times in total.

TI 55, HP16C, HP41C, DM42, APPLE ][, TRS-80, ATARI 800XL, ATARI 520ST, XEROX 1186 DANDELION, SYMBOLICS 3640, TI EXPLORER II
BLOG: https://yazuu.org/en/showblog_public.php?user=1&blog=
User avatar
Stumpfenstiel
Posts: 10
Joined: Sun Feb 07, 2021 10:53 pm

Re: PUSH and POP stack routines

Post by Stumpfenstiel »

This is great, thank you!
Panchdara
Posts: 148
Joined: Sat May 15, 2021 9:02 am

Re: PUSH and POP stack routines

Post by Panchdara »

Tried it here:

https://technical.swissmicros.com/decoders/dm42/

failed.
PushPullErr.jpg
PushPullErr.jpg (196.51 KiB) Viewed 2573 times
User avatar
lispm
Posts: 27
Joined: Tue Jun 29, 2021 2:23 pm
Location: Germany

Re: PUSH and POP stack routines

Post by lispm »

As far as I know does the programming tool not supoort any of the free42 new features yet.
And my little program makes heavy use of features like FUNC, APPEND, REV, NEWLIST.....
Perhaps one can ask SwissMicros to keep the programming tool up to date.

I usually paste the code to my Ubuntu or Raspi (Windows and Mac work as well) Version and create the raw from there.

TI 55, HP16C, HP41C, DM42, APPLE ][, TRS-80, ATARI 800XL, ATARI 520ST, XEROX 1186 DANDELION, SYMBOLICS 3640, TI EXPLORER II
BLOG: https://yazuu.org/en/showblog_public.php?user=1&blog=
Panchdara
Posts: 148
Joined: Sat May 15, 2021 9:02 am

Re: PUSH and POP stack routines

Post by Panchdara »

Thanks Lispm. Got it now. Thank you. 👍
User avatar
lispm
Posts: 27
Joined: Tue Jun 29, 2021 2:23 pm
Location: Germany

Re: PUSH and POP stack routines

Post by lispm »

For your convenience I added a download link here (PUSHPOP.raw) and I will change the original post also.

TI 55, HP16C, HP41C, DM42, APPLE ][, TRS-80, ATARI 800XL, ATARI 520ST, XEROX 1186 DANDELION, SYMBOLICS 3640, TI EXPLORER II
BLOG: https://yazuu.org/en/showblog_public.php?user=1&blog=
Panchdara
Posts: 148
Joined: Sat May 15, 2021 9:02 am

Re: PUSH and POP stack routines

Post by Panchdara »

👍👍
dlachieze
Posts: 613
Joined: Thu May 04, 2017 12:20 pm
Location: France

Re: PUSH and POP stack routines

Post by dlachieze »

Nice routines. There are some optimizations possible, for example in PUSH you use the flag 25 but don’t test it.
Here is a shorter version of your routines:

Code: Select all

00 { 73-Byte Prgm }
01▸LBL "PUSH"
02 FUNC 10
03 SF 25
04 RCL "μ"
05 FC?C 25
06 NEWLIST
07 LIST?
08 GTO 01
09 DROP
10 NEWLIST
11▸LBL 01
12 X<>Y
13 APPEND
14 STO "μ"
15 RTN

16▸LBL "POP"
17 FUNC 01
18 RCL "μ"
19 LENGTH
20 X<>Y
21 0=? ST Y
22 RTNNO
23 LASTx
24 REV
25 HEAD ST X
26 X<>Y
27 REV
28 STO "μ"
29 DROP
30 END
DM42: 00425 - DM41X: β00066 - WP43: 00042
User avatar
lispm
Posts: 27
Joined: Tue Jun 29, 2021 2:23 pm
Location: Germany

Re: PUSH and POP stack routines

Post by lispm »

Dear dlachieze

Code: Select all

 1
 XEQ "PUSH"
 XEQ "POP"
returns error

"too few Arguements" in NSTK
"Invalid Type" in 4STK

at least with my Free42 3.0.10 on Ubuntu and Android

TI 55, HP16C, HP41C, DM42, APPLE ][, TRS-80, ATARI 800XL, ATARI 520ST, XEROX 1186 DANDELION, SYMBOLICS 3640, TI EXPLORER II
BLOG: https://yazuu.org/en/showblog_public.php?user=1&blog=
Thomas Okken
Posts: 1100
Joined: Tue May 02, 2017 5:48 pm
Location: Netherlands
Contact:

Re: PUSH and POP stack routines

Post by Thomas Okken »

Personally, I wouldn't bother checking that μ is a list, only that it exists. Using EXTEND simplifies the code as well:

Code: Select all

00 { 55-Byte Prgm }
01▸LBL "PUSH"
02 FUNC 10
03 NEWLIST
04 X<>Y
05 APPEND
06 SF 25
07 RCL "μ"
08 FS?C 25
09 EXTEND
10 STO "μ"
11 RTN
12▸LBL "POP"
13 SF 25
14 HEAD "μ"
15 GTO 00
16 CF 25
17 RTNNO
18▸LBL 00
19 FC?C 25
20 RTNNO
21 RTNYES
22 END
Last edited by Thomas Okken on Tue Mar 22, 2022 2:22 am, edited 1 time in total.
Post Reply