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: 03-30-2020 04:31 PM by Artur - Brasil.)
Post: #41
RE: HP 41 - branching to local label and return stack
Some few fixes to my routine of sofmenus for HP-41CX (C/CV with X-Functions): - Mars, 30th

xxxx - remove
xxxx - insert or modify

Original post:
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

2 STO 41 name of caller program
3 AVIEW
4 XEQ "LR"
5 STOP
6 XEQ "SR"
7 0
8 RTN R/S will return 0 to caller program
9 LBL A starts the function menu
10 1
11 STO 42 numeric lbl for selected function
12 XEQ "SR"
13 RTN
14 LBL B
15 2
16 STO 42
17 XEQ "SR"
18 RTN
19 LBL C
20 3
21 STO 42
22 XEQ "SR"
23 RTN
24 LBL D
25 4
26 STO 42
27 XEQ "SR"
28 RTN
29 LBL E
30 5
31 STO 42
32 XEQ "SR"
33 RTN .end of equations menu
34 LBL "SFT1" prepares the first menu, but does not show it
35 CF 01 Flag 01 - controls when is possible to SOLVE for a variable;
36 CF 02 Flag 02 - controls if presenting second menu
37 CF 05 Flag 05 - if there is a second menu

38 STO 43 stores the function name for SOLVE
39 ASTO 47 stores 6 first characters of first variables menu
40 ASHF
41 ASTO 48 stores 6 middle characters of first variables menu
42 ASHF
43 ASTO 55 stores 6 last characters of first variables menu
44 RTN
45 LBL "SFT2" starts second menu os variables
46 ALENG
47 X=0?
48 GTO 07 no second menu? gto 07
49 SF 05
50 ASTO 49 stores 6 first characters of first variables menu
51 ASHF
52 ASTO 50 stores 6 middle characters of first variables menu
53 ASHF
54 ASTO 56 stores 6 last characters of first variables menu
55 LBL 07
56 XEQ "LR"
57 LBL 15
58 CLA
59 ARCL 47 mount first variable menu
60 ARCL 48
61 ARCL 55
62 FS? 05 is there a second variable menu?
63 XEQ 05 will add a > at right of menu, indicating to user the existence of second menu
64 GTO 06 shows the menu (first in this call, but this same label shows the second too)
65 LBL 16 else, will try to show second menu
66 FC? 05
67 GTO 15 but there is no second menu, go back to first one then.
68 SF 02 no, no - there is the second menu - we are showing it now.
69 CLA
70 40
71 XTOA adds at left < indicating there is a first menu
72 ARCL 49
73 ARCL 50
74 ARCL 56 mount the second menu
75 LBL 06 shows menu and wait for user entry
76 CF 22
77 PROMPT
78 FC?C 01 pressed R/S
79 GTO 06 but no variable wa shown/edited, a mistake and shows menu again
80 XEQ "SR" the user pressed R/S and there was a check/edit variable.
81 RTN Return to caller progIt will check variables and call again SFTMenu to SOLVE it.
82 LBL 06 well, R/S was pressed by mistake, but which menu shall we show?
83 FS? 02 second menu?
84 GTO 16 so, goto show second variable menu;
85 GTO 15 no, no, it was shown the first one, return to it!
86 LBL I change from/to 1st-2nd menus
87 CF 01

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 SOLVEIt has a strange behavior to try zero and
152 50000 this was causing troubleSo, I defined these two valuesAny better suggestion?

151 RCL IND 44
152 ENTER
153 9
154 +

155 SOLVE
156 GTO 02 if a root was found.
157 NO SOL no root was found, just a message and return to caller program.
158 AVIEW
159 RTN
160 LBL "SFT4"
161 AVIEW
162 BEEP
163 RTN
164 LBL 02
165 RCL IND 44
166 ABS in my equations, all values are positive. Here you must verify your situation.
167 STO IND 44 stores the module of real solution
168 BEEP
169 PSE
170 END returns to caller program (will show variables menu again)


Attached File(s)
.pdf  SoftMenu_v2_1.PDF (Size: 13.72 KB / Downloads: 0)

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)