Post Reply 
HP 41 - branching to local label and return stack - FINAL RESULTS AND PROGRAMS
06-23-2019, 02:24 AM (This post was last modified: 06-23-2019 02:35 AM by Artur - Brasil.)
Post: #41
RE: HP 41 - branching to local label and return stack
Well, now the code for SoftMenu and Logic. Another extremely important routine is LR and SR, from CCD module, which Sylvain provide to me in barcodes. Without these routines that save and restore de return stack of XEQs, these programs would not be possible.

SFTMEN uses registers 01 to 20 for storing data for variables of equations;
My others programs (previous to SFTMEN) used other registers - up to 40. I kept most of them and decided use for SFTMEN controls registers from 41 to 56 (16 registers).
SOLVE also use a lot of registers, so you need to free registers or space to it too.


1 LBL "SFTMEN"
2 CF 01 ................. Flag 01 - controls when is possible to SOLVE for a variable;
3 CF 02 ................ Flag 02 - controls if presenting second menu
4 CF 05 ................ Flag 05 - if there is a second menu
5 STO 41 .............. name of caller program
6 AVIEW
7 XEQ "LR"
8 STOP
9 XEQ "SR"
10 0
11 RTN ................... R/S will return 0 to caller program
12 LBL A ................. starts the function menu
13 1
14 STO 42 ............... numeric lbl for selected function
15 XEQ "SR"
16 RTN
17 LBL B
18 2
19 STO 42
20 XEQ "SR"
21 RTN
22 LBL C
23 3
24 STO 42
25 XEQ "SR"
26 RTN
27 LBL D
28 4
29 STO 42
30 XEQ "SR"
31 RTN
32 LBL E
33 5
34 STO 42
35 XEQ "SR"
36 RTN .................end of equations menu
37 LBL "SFT1" ...... prepares the first menu, but does not show it
38 CF 05
39 STO 43 ........... stores the function name for SOLVE
40 ASTO 47 ......... stores 6 first characters of first variables menu
41 ASHF
42 ASTO 48 ......... stores 6 middle characters of first variables menu
43 ASHF
44 ASTO 55 ......... stores 6 last characters of first variables menu
45 RTN
46 LBL "SFT2" ..... starts second menu os variables
47 ALENG
48 X=0?
49 GTO 07 ...... no second menu? gto 07
50 SF 05
51 ASTO 49 ......... stores 6 first characters of first variables menu
52 ASHF
53 ASTO 50 ......... stores 6 middle characters of first variables menu
54 ASHF
55 ASTO 56 ......... stores 6 last characters of first variables menu
56 LBL 07
57 XEQ "LR"
58 LBL 15
59 CLA
60 ARCL 47 .... mount first variable menu
61 ARCL 48
62 ARCL 55
63 FS? 05 ..... is there a second variable menu?
64 XEQ 05 .... will add a > at right of menu, indicating to user the existence of second menu
65 GTO 06 .... shows the menu (first in this call, but this same label shows the second too)
66 LBL 16 .... else, will try to show second menu
67 FC? 05
68 GTO 15 .... but there is no second menu, go back to first one then.
69 SF 02 ...... no, no - there is the second menu - we are showing it now.
70 CLA
71 40
72 XTOA ...... adds at left < indicating there is a first menu
73 ARCL 49
74 ARCL 50
75 ARCL 56 ... mount the second menu
76 LBL 06 ..... shows menu and wait for user entry
77 CF 22
78 PROMPT
79 FC?C 01 ... pressed R/S
80 GTO 06 .... but no variable wa shown/edited, a mistake and shows menu again
81 XEQ "SR" .. the user pressed R/S and there was a check/edit variable.
82 RTN ... Return to caller prog. It will check variables and call again SFTMenu to SOLVE it.
83 LBL 06 ... well, R/S was pressed by mistake, but which menu shall we show?
84 FS? 02 ... second menu?
85 GTO 16 ... so, goto show second variable menu;
86 GTO 15 ... no, no, it was shown the first one, return to it!
87 LBL I ..... when user was prompted for an action, he/she desired to change 1st-2nd menus
88 FS?C 02
89 GTO 15 .. he/she was in second - go to first
90 GTO 16 .. he/she was in first - go to second
91 LBL 05 ... adds < to menu
92 41
93 XTOA
94 RTN
95 LBL J ... when prompted for variable, user discovered he/she selected wrong equation
96 GTO IND 41 ... go back to equation menu
97 LBL A .... depressed A key in variables menu
98 1
99 GTO 08
100 LBL B .... depressed B key in variables menu
101 2
102 GTO 08
103 LBL C .... depressed C key in variables menu
104 3
105 GTO 08
106 LBL D .... depressed D key in variables menu
107 4
108 GTO 08
109 LBL E .... depressed Ekey in variables menu
110 5
111 GTO 08
112 LBL a .... depressed a key in variables menu
113 11
114 GTO 08
115 LBL b .... depressed b key in variables menu
116 12
117 GTO 08
118 LBL c .... depressed c key in variables menu
119 13
120 GTO 08
121 LBL d .... depressed d key in variables menu
122 14
123 GTO 08
124 LBL e .... depressed e key in variables menu
125 15
126 LBL 08
127 FC? 02
128 GTO 01
129 5 .... adjusts the register number for a...e - the register for A...E shifted by 5
130 +
131 LBL 01
132 STO 44 ... stores the register number for variable - IN YOUR PROGRAM YOU MUST USE IT
133 FS? 22 ... did user entry any data?
134 GTO 03 ... will store it
135 RCL IND 44 ... else, just show previous value for variable selected
136 PSE
137 SF 01 ... now this variable can be solved
138 FS? 02 ... returns to variables menu: 1st or 2nd
139 GTO 16
140 GTO 15
141 LBL 03 ... stores the value user typed in
142 X<>Y
143 STO IND 44 ... using the reg 44 as indirect address
144 SF 01 ... also turns on the solve for this variable
145 FS? 02 ... returns to variables menu, 1st or 2nd
146 GTO 16
147 GTO 15
148 LBL "SFT3" .... here we call SOLVE from Advantage
149 CLA
150 ARCL 43 ... recall the function lbl
151 1 ......... two initial guesses for SOLVE. It has a strange behavior to try zero and
152 50000 ... this was causing trouble. So, I defined these two values. Any better suggestion?
153 SOLVE
154 GTO 02 ... if a root was found...
155 "NO SOL." ... no root was found, just a message and return to caller program.
156 AVIEW
157 RTN
158 LBL "SFT4"
159 AVIEW
160 BEEP
161 RTN
162 LBL 02 .... in my equations, all values are positive. Her you must verify your situation...
163 RCL IND 44
164 ABS
165 STO IND 44 stores the module of real solution
166 BEEP
167 PSE
168 END ... returns to caller program (will show variables menu again)

ARTUR MARIO JUNIOR
BRAZIL
+55 31 99850-2280
arturmariojr@gmail.com
Find all posts by this user
Quote this message in a reply
06-23-2019, 02:40 AM
Post: #42
RE: HP 41 - branching to local label and return stack
Now, the LOGIC program.
Advantage and HP41 have some logic functions, but they were created for test 0 and 1 (binary information) as I understand.
My routines check if the data you passed to them are 0 or different of 0 and do not skip next line of program, they return 1 or 0 (true or false). A very simple idea, isn't it? I don't believe no one has ever needed such functions!!

1 LBL "LOGIC"
2 LBL "XORV"
3 SF 03
4 LBL "XORR"
5 X=Y?
6 GTO 01
7 R^
8 X=Y?
9 GTO 01
10 X<>Y
11 R^
12 LBL 01
13 RDN
14 RDN
15 FS?C 03
16 GTO 12
17 RCL IND X
18 RCL IND Z
19 GTO 12
20 LBL "XORA"
21 ATOX
22 STO L
23 CLX
24 89
25 ST- IND L
26 CLX
27 LASTX
28 X>0?
29 GTO 01
30 X<0?
31 GTO 02
32 RDN
33 X<>Y
34 GTO 01
35 LBL 02
36 RDN
37 LBL 01
38 RDN
39 LBL "XOR2"
40 LBL 12
41 XEQ 10
42 GTO 01
43 LBL "XOR3"
44 XEQ 10
45 GTO 02
46 LBL "XOR4"
47 XEQ 10
48 X<>Y
49 XEQ 10
50 +
51 LBL 02
52 X<>Y
53 XEQ 10
54 +
55 LBL 01
56 X<>Y
57 XEQ 10
58 +
59 X=0?
60 RTN
61 1
62 X=Y?
63 RTN
64 STO- X
65 RTN
66 LBL "X#0?L"
67 LBL 10
68 X#0?
69 GTO 01
70 RTN
71 LBL 01
72 1/X
73 ST/ X
74 RTN
75 LBL "X=0?L"
76 LBL 11
77 X=0?
78 GTO 01
79 1/X
80 ST- X
81 RTN
82 LBL 01
83 1
84 END

ARTUR MARIO JUNIOR
BRAZIL
+55 31 99850-2280
arturmariojr@gmail.com
Find all posts by this user
Quote this message in a reply
06-23-2019, 04:03 PM
Post: #43
RE: HP 41 - branching to local label and return stack - FINAL RESULTS AND PROGRAMS
(06-23-2019 02:24 AM)Artur - Brasil Wrote:  Another extremely important routine is LR and SR, from CCD module ...
Hello Artur,
Thank you for sharing your ideas and your documented code. 8-)
For the record, these routines (LR & SR) comes from the PPC ROM module created by the PPC User's Club in California USA.
Sylvain
Find all posts by this user
Quote this message in a reply
Post Reply 




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