Post Reply 
HP 41 - branching to local label and return stack - FINAL RESULTS AND PROGRAMS
06-21-2019, 01:42 AM (This post was last modified: 06-21-2019 01:55 AM by Artur - Brasil.)
Post: #33
RE: HP 41 - branching to local label and return stack
Hi Sylvain and all guys that helped me in this journey!

The soft menu for 41 is working now! These days I was busy at faculty but, in mean time, I could refine and finish it.
I believe it is a good aproach for soft menus. With it I made some few other programs: CPLX - my approach to deal with complex numbers and some routines to show and get data; LOGIC - some routines to make XOR tests. Of course, LR and SR were too fundamental for SFTMEN.

Before explaining the routines, let me present what was my problem:
- calculating for transformers, motors, magnetism.
- transformers have many equations for calculating current, voltage, magnetic field, magnetic densit flux, etc. The other matters also have their equations.
- each equation has its own variables (sometimes shared with other functions). I would like to preserve, when possible, the same register to hold same variable between formulas. Ex: A = B*C and D = B*H;

- where I could merge functions, I did it. Most like the big equation for calculating TVM in HP-12C, where they merged in only one equation the functions for PV, FV, PMT, I and N. But merging many equations in only one brought some troubles. Let's put as this: A = B/D, but A=E/F too. So, I make: A - B/D - E/F = 0, but user should not supply both B and E at same time, or calculus for A would be wrong. So, I need to test if A, B and E were given at same time and not allow it (XOR between then); also, if D or F were not given, when SOLVE evaluates the equation, a division by zero would happen - for this, the solution is to test the variable and fit it with 1 if not given, independent of given B or E.
For "unicity" tests I make a LOGIC program, with some global routines: XORV, XORR, XORA - makes XOR test on stack, comparing X with Y, Z and T registers, directly by the values they hold, or indirectly, by registers numbers they point to, or by a reference in ALPHA. The difference here is that I do not test 1 and 0, but general numeric values and get back 0 or 1. I could not find such routines in Advantage or Math modules;

The HP41 soft menus offers:
Two levels of menus: first level is a parent menu up to 5 options - I call each option a function or equation. It receives these options in a string "F1 F2 F3..." - remember: up to 5 entries and you have only 12 characters in display (you may add . , or : and they do not occupy a character place)!
From first level menu, I get: 0 - none equation selected - or 1...5 and you must redirect (IND X) to a respective numbered label in your main program.
Each of these labels represents the of variables of formula, the validation over data and a global label to calculate the equation in order it gives 0 (I'll use SOLVE for this).

Your caller program must be as this:
- mount the string for parent menu:

"FN1 FN2 ...FN5"
XEQ "SFTMENU" I'll prompt menu and wait the user press A - E - returns 1 - 5; or presst R/S - returns 0;
GTO IND X to the choosen function (a numeric local label from 1-5)

Second level: variables menu - up to 2 groups of menus: A - E or a - e for first group menu; and A - E or a - e for second group menu, representing variables of formulas, or topics, selected in first level. Also the name of function (global label) that will calculate such formula.

You have up to 20 "variables" entries. Each one has a fixed associated register, from 1 - 5, 6 - 10 (A-E, first and second menus), and 11 - 15 and 16 - 20 (a-e, first and second menus).

For that formula I put before:
A - B/D - E/F = 0 the menu should be:

"A B D E F" - no need of second menu neither shift soft key(a-e)

But if other equations share these variables too and have new ones?
For example:
A - F/H = 0

A and F are in first formula, associated to A and E menu keys and so to 1 and 5 registers.
So, the menu can be like this for this second equation:
"A ^H - - F" - respectively letters A, b, - , - , E. Here the use of shift key preserve the original registers 1 and 5 to A and F. H get the register 12.

When the variables menu is shown, the user can:
- just press the associated key: the value previously existent will be shown;
- type in a value and press the associated key: this new value will be stored for respective variable;
When he/she takes one of these actions, flag 1 is turned on;
- finally, press R/S: if flag 1 is on, the solution for last variable whose soft key was pressed will be calculated; if flag 1 is off, it was a mistake and nothing happens.
If there is a second menu of variables, a > symbol is added to string of menus you provided. User must press I to show this second menu. In this case, a < symbol is added to it, remembering user that there exists a first menu (I returns to first menu). Also, if user sees that he/she selected the wrong formula, just press J and returns to functions menu.

If the solve is to be calculated, the routine returns to your main program, when you can:
- test for unicity of variables;
- if inconsistencies were found, you can mount a message, call a routine (XEQ "SFT4") to show it and show again variables menu;
- if no inconsistencies were found, check the divisions by zero and fix them:
By example: A/B - A is stored in register 1 and B in two, so:
This will put 1 in B if it has nothing (0), but will keep original value if it has one.

Everything ok? XEQ "SFT3" for SOLVE the equation;

It seems difficult, isn't it? But, actually, it is really very easy!
Next post I'll show an example.

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-21-2019 01:42 AM

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