Post Reply 
HP 41 - branching to local label and return stack - FINAL RESULTS AND PROGRAMS
06-22-2019, 07:31 PM (This post was last modified: 06-22-2019 10:07 PM by Artur - Brasil.)
Post: #38
RE: HP 41 - branching to local label and return stack
The caller program:
001 LBL "MAGN" -my program to calculate magnetism problems
002 LBL 15 - a numeric label to save on internals GoTo
003 "MAGN" - repeat the program name,so I can return from menu
004 ASTO X - copy ALPHA to X register
005 "FL PM RL H" - the equations menu
006 XEQ "SFTMEN" - call the main menu program.

The SFTMEN will save program name and menu in registers and will show the parent menu with name of equations (FLux, PerMeability, ReLutance and Field (H))

The user can press from A..D or R/S. It will be returned 0 (nome selected) or 1...5 for the equation selected.
Back to your program:

007 X=0? user didn't select any equation
008 GTO "MAQELE" I'll return to a kind of problems manager (or just put RNT to finish)
009 GTO IND X the user got some equation. It will be executed now.

Here the routine for first equation: magnetic flux

010 LBL 01 - the same number as the position of formula name's in equations menu
011 "FLX" - the global name SOLVE will execute. It will be at the end of this routine (line 32)
012 ASTO X - copy ALPHA to X register
013 "^% B:A:R:^FMM" - the variables menu
014 XEQ "SFT1" - the routine that will start mount the variables menus

SFT1 does not interact with user and returns to caller program:

015 CLA - this equation does not have a second menu, so clean ALPHA
016 XEQ "SFT2" - call the routine for second menu. It will show the first menu and works transition from 1st to 2nd if any.

User can press A-E or a-e, as indicated by display.
Pressing such keys will show any previous value for selected variable;
User can input some value (I'll test flag 22) and press the soft key. I'll save the new value to its register;
When the user does any of these two operations (recall or store), I'll turn on flag 01.
User can also press R/S: if flag 01 is on, I'll solve for the last variable seem/stored; if flag 01 is off, this represents a mistake and menu will be shown again.
Finally, user can press I to go to second menu if there is one (or come from 2nd to 1st menu back) or press J to return to parent menu (equations menu).

Resuming:
A...E; a...e - shows the stored value for the variable; turns on flag 01
number A...E; a...e - stores a new value for variable; turns on flag 01
R/S - if flag 01 is on, will solve for the last seem/stored variable;
I- goes to second/first menu of variables;
J - returns to equations menu (parent menu)

This is all you need for calling soft menus. Now, we will work on data validation.

This point of program only will execute if user selects some variable to solve.
Let's remember the variables versus registers: 11 - flux; 02 - B; 03 - A; 04 - R; 15 - FMM;
Equation: φ - B.A+Fmm/R = 0

First test: XOR over possible variables and the one selected for solving. See that one test is not for a simple variable, but for B.A, so, I have to use the function that tests values in stack (I have others similar functions that can deal with registers numbers, instead of values stored).

017 RCL 11 ............. φ
018 RCL 02 ............... B
019 RCL 03 ................. A
020 * ......................... B.A
021 RCL 15 ..................... FMM
022 RCL IND 44

Register 44 stores the actual register (variable) that will be solved for. So, I'll recover the value stored in that variable.
The next step (XORV) is a function of mine. It will test on stack: X must have the value of variable to solve for. Other levels have it too and two others values. Only one of these can be different of zero.

023 XEQ "XORV"
024 X=0? ................if XORV returns zero is because we have more variables than needed
025 GTO 11 ............ user will get a message to zero any variable

2nd test: no denominator can be zero
026 RCL 04 ..... R
027 X=0?
028 1 .............. if zero, puts 1 in it
029 STO 04

030 XEQ "SFT3" ....... now, let's solve for selected variable
031 GTO 01 . after solving for variable, returns to the function and begins everything again

032 LBL 11 .... for treating the errors above
033 "ZERE %:B*A:FMM"
034 XEQ "SFT4"
035 GTO 01

036 LBL "FLX" ... here the function itself: φ - B.A+Fmm/R = 0 - see line 011.
037 STO IND 44 ... as we are using SOLVE, it will bring the value to test on function.
Store it in IND 44, always.

038 RCL 11 .......φ
039 RCL 02 ....... B
040 RCL 03 ...... A
041 * ........ B.A
042 - ........ φ - B.A
043 RCL 15 ..... FMM
044 RCL 04 ..... R
045 / ........... FMM/R
046 - ....... φ - B.A+Fmm/R
047 RTN

This was the first equation.

ARTUR MARIO JUNIOR
BRAZIL
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: HP 41 - branching to local label and return stack - Artur - Brasil - 06-22-2019 07:31 PM



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