HP 41  branching to local label and return stack  FINAL RESULTS AND PROGRAMS

05212019, 11:12 AM
(This post was last modified: 05212019 11:36 AM by Artur  Brasil.)
Post: #21




RE: HP 41  branching to local label and return stack
(05202019 11:48 PM)Sylvain Cote Wrote: Artur,Sylvain, many thanks for your efforts! Great job!! I got the code into my HP. It lists as this bellow. Just some thoughts: there's no return between such programs. One acts as part of another. So, I'll try them today and see what happens! Many thanks! LBL "SR" SIGN SF 10 RDN RCL b STO M RDN FC?C 10 RTN "***" RCL IND L ISG L "" X<> IND L STO N "**" X<> IND L STO O "**" X<> O STO a X<> N CLA // see that there isn't RTN to close label SR!! LBL "Sb" STO b // again there isn't RTN to close label Sb!! I believe it's because the program pointer will jump to the new address in b!! LBL "LR" SIGN RDN + RCL a STO N RDN RCL b X<> M STO 0 ASTO IND L ISG L "" "*****" STO O ASTO IND L RDN CLA RTN END //This I put by myself ARTUR MARIO JUNIOR BRAZIL 

05212019, 01:45 PM
(This post was last modified: 05212019 11:23 PM by Sylvain Cote.)
Post: #22




RE: HP 41  branching to local label and return stack
Hello Artur,
I am at work and cannot do a line by line analysis, but see my notes below ... Sylvain Click on "View a Printable Version" below to see the complete source code Code: LBL "SR" edit: STO b comment corrected 

05212019, 11:17 PM
Post: #23




RE: HP 41  branching to local label and return stack
The following are extract from PPC ROM manual:


05222019, 12:28 AM
Post: #24




RE: HP 41  branching to local label and return stack
(05212019 01:45 PM)Sylvain Cote Wrote: Correction: not "could" be removed, but "should" be removed. END is not just a marker that indicates where a program ends. It is an executable instruction, and when it is executed, it performs EXACTLY the same operation as RTN. There is never, ever, any reason to put a RTN right before an END. Never ever. And when you do, a kitten dies somewhere. 

05222019, 01:44 AM
Post: #25




RE: HP 41  branching to local label and return stack
(05222019 12:28 AM)Thomas Okken Wrote: There is never, ever, any reason to put a RTN right before an END. Never ever. And when you do, a kitten dies somewhere. Dammit! I now have to clean up the water I just spit all over my desk, as I was drinking when reading this. Thanks for that. Bob Prosperi 

05222019, 01:50 AM
(This post was last modified: 05222019 01:52 AM by Artur  Brasil.)
Post: #26




RE: HP 41  branching to local label and return stack
Hi, guys!
In a simple test program, the routines worked fine: The program will show A B (in a subroutine) and user keys A or B. Such branches shall return 1 or 2 to main program, which, in turns, adds 1 to whatever returns. LBL "AA" XEQ "BB" 1 // here if RTN from BB works fine, I'll add 1 to the number returned from there. + RTN LBL "BB" 1 //needed by LR  the first of two regs to store a and b XEQ "LR" // LR kills alpha register, so, I believe it's better call LR before prompting messages "A B" PROMPT LBL A 1 //needed by SR  the first of two regs that stored a and b XEQ "SR" //gets back the return stack  we hope! 1 RTN // this RTN would never work in a "normal" program LBL B 1 XEQ "SR" 2 END //won't put RTN where it is not neccessary any more! Whithout shynt instructions, // program simple would stop here. It worked very fine! I'll add the calling for those routines in my soft menu. Unfortunatelly, this will cost a lot of bytes, which were at limit to use short local labels ... if someone interested in my routine, I'll could explain and give some examples. May be someone could improve it and we finally got a routine for soft menus in 41C! Many thanks to Sylvain for his precious support  without you, I would retire my 41 again .... ARTUR MARIO JUNIOR BRAZIL 

05222019, 02:00 AM
Post: #27




RE: HP 41  branching to local label and return stack
I forgot to comment something strange about NovRAM:
I just saved the program SR (it has the others: LR and Sb) to NovRAM. So, I deleted the SR from main memory. By mystake, I delete the program AA where I called the synthetic routines, so, I was retype it. Well, when I typed: XEQ ALPHA LR ALPHA, the calculator show XEQ IND A !!! The same for XEQ ALPHA SR ALPHA (the register after IND I don't remember well). Running program, it didn't work as desired. Some explanation? I'll have to keep programs in main memory? Diego says we can call a program stored in NovRAM without problems. Have I missed something? Best wishes Artur ARTUR MARIO JUNIOR BRAZIL 

05222019, 02:02 AM
Post: #28




RE: HP 41  branching to local label and return stack
(05222019 12:28 AM)Thomas Okken Wrote:I was just afraid to remove some byte from a program with synthetic instructions...(05212019 01:45 PM)Sylvain Cote Wrote:Correction: not "could" be removed, but "should" be removed. ARTUR MARIO JUNIOR BRAZIL 

05222019, 07:08 PM
Post: #29




RE: HP 41  branching to local label and return stack
(05222019 02:00 AM)Artur  Brasil Wrote: Some explanation? I'll have to keep programs in main memory? Diego says we can call a program stored in NovRAM without problems. Have I missed something?Hello Artur, There are fundamental differences between main RAM and HePaX RAM (or NoVRAM HePaX simulation). I need to do some investigation on how HePaX FOCAL adresses are pushed in the return stack before going further. I should be able to check it tonight (GMT4h) and will come back with an explanation. Sylvain 

05232019, 02:24 AM
Post: #30




RE: HP 41  branching to local label and return stack
Hello Artur,
I have investigated the return stack for both RAM and HePaX RAM and it should works for both. (05222019 02:00 AM)Artur  Brasil Wrote: I forgot to comment something strange about NovRAM:I just did the same thing and it works on my side. Do the following:
(05222019 02:00 AM)Artur  Brasil Wrote: I'll have to keep programs in main memory?nop (05222019 02:00 AM)Artur  Brasil Wrote: Diego says we can call a program stored in NovRAM without problems.yep I have done the following test procedure:
Test program: Code: 01 LBL "RS9" 

05232019, 12:11 PM
Post: #31




RE: HP 41  branching to local label and return stack
(05232019 02:24 AM)Sylvain Cote Wrote:Hi, Sylvain!! Wow, you're working hard!!! Well, for lines 51 and 57, you typed: XEQ ALPHA LR ALPHA and same to other line? The calculator so showed XROM "LR" ?!! I'll try again, as mine showed an strange code instead of XROM LR... Best wishes!! Artur ARTUR MARIO JUNIOR BRAZIL 

05232019, 11:38 PM
(This post was last modified: 05232019 11:47 PM by Sylvain Cote.)
Post: #32




RE: HP 41  branching to local label and return stack
(05232019 12:11 PM)Artur  Brasil Wrote: Well, for lines 51 and 57, you typed: XEQ ALPHA LR ALPHA and same to other line? The calculator so showed XROM "LR" ?!!To keep it simple, an HePaX module behaves like ROM but with RAM. All files in HePaX RAM gets an entry in the module FAT table and thus get a XROM number. In my case ...


06212019, 01:42 AM
(This post was last modified: 06212019 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 HP12C, 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: LBL "MAGNET" "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; X=0? RTN GTO IND X to the choosen function (a numeric local label from 15) 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 (AE, first and second menus), and 11  15 and 16  20 (ae, 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(ae) 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: RCL B X=0? 1 STO B 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. ARTUR MARIO JUNIOR BRAZIL 

06212019, 10:11 PM
Post: #34




RE: HP 41  branching to local label and return stack
I've read through many of the solutions and, I believe the "KISS" (keepitsimple..) is missing. See my program here:
https://www.hpmuseum.org/software/41/41tmgr15.htm The sequence I use for softkeys simply places a number in X. Code:


06212019, 11:07 PM
Post: #35




RE: HP 41  branching to local label and return stack
(05222019 12:28 AM)Thomas Okken Wrote: There is never, ever, any reason to put a RTN right before an END. Never ever. And when you do, a kitten dies somewhere. Gene: And, for the record :) the PPC ROM routine does not have the RTN END combination here. To my knowledge (?) there is only one "bug" in the PPC ROM code. The LBL BE routine has a GTO BE instruction at the end of its loop instead of a GTO local label. Rather unfortunate, since it must travel the global alpha label chain each time...and a number of routines use the BE routine. But I am not aware of any other bug ? 

06222019, 01:01 PM
(This post was last modified: 06222019 07:43 PM by Artur  Brasil.)
Post: #36




RE: HP 41  branching to local label and return stack
(06212019 10:11 PM)Bill Duncan Wrote: I've read through many of the solutions and, I believe the "KISS" (keepitsimple..) is missing. See my program here:Hi, Bill That's the idea, but we have just one line in display, so I decided do not use the keys from F to H, as user can't see what variables are associated to them directly. Instead, I make two sequences of menu. Beyond this, you can mix with a  e (shift keys). This gives you, in principle, 20 variables! Let's study a simple caller programm: I need to solve four problems: First one: magnetic flux φ = B.A > φ  B.A = 0 φ = Fmm/R > φ  Fmm/R =0 , let's make just one equation for both functions: φ  B.A+Fmm/R = 0 But we can't have φ, B.A and Fmm at same time. If we will calculate φ, only B.A or Fmm can be given; if we calculate B, only one of φ or Fmm, and so on. So, an XOR on three combining two of them giving the another!!! And you don't know which one will be asked to be solved for! Also, R can't be equals to 0: R<>0 Second one: permeability u = B / H ur = u/u0 > u = ur.uo (u + uo.ur)  B/H = 0 Same restrictions: XOR (u, uo.ur, B); H <> 0 Third one: relutance R = L/(u.A) ur = u/uo => u = ur.uo (relative permeability and absolute  uo is a constant) R  L/(u+uo.ur).A = 0 (problems usually have ur, but...) Again, XOR(R, u, uo.ur) A <> 0 The fourth one: magnetic field H = N*I/L Fmm = N*I Let's put in order... H  (Fmm+NI)/L = 0 XOR(H,Fmm, N*I). L <> 0. Next post I'll present the variables/keys to these formulas (my wife wants to go window shopping now ...) Have you seen, Bill, as the problem is bigger and we can't waste memory repeating so many menus? See you soon!! ARTUR MARIO JUNIOR BRAZIL 

06222019, 04:16 PM
(This post was last modified: 06222019 04:40 PM by Artur  Brasil.)
Post: #37




RE: HP 41  branching to local label and return stack
Well, let's study the variables allocation in registers.
Remember: I'll try do not use the one register for two variables. First menu can have 5 keys  AE or ae or mix of them; The same for second menu. For MAGNETIC FLUX: φ  B.A+Fmm/R = 0 +++++ MENU  REG  A...B  REG  a...e  1st....01...  ....11... % .. % represents the theta letter! .......02... B ....12........ .......03... A ....13........ .......04... R ....14........ .......05..........15.. FMM . 2nd....06..........16........ .......07..........17........ .......08..........18........ .......09..........19........ .......10..........20........ User will see:  B A R ^FMM A B C D E Key A has no meaning in this menu. For PERMEABILITY: (u + uo.ur)  B/H = 0 +++++ MENU  REG  A...B  REG  a...e  1st....01... u ....11........ .......02..........12... L .. .......03... A ....13........ .......04... R ....14........ .......05.. ur ....15........ 2nd....06..........16........ .......07..........17........ .......08..........18........ .......09..........19........ .......10..........20........ User will see: u ^L A R uR A b .C D E (The dot is just to align here in my post) For RELUTANCE: R  L/(u+uo.ur).A = 0 +++++ MENU  REG  A...B  REG  a...e  1st....01... u ....11........ .......02...  ....12........ .......03..........13... H .. .......04... R ....14........ .......05.. ur ....15........ 2nd....06..........16........ .......07..........17........ .......08..........18........ .......09..........19........ .......10..........20........ User will see: u  ^H R uR A B .c D E (The dot is just to align here in my post) For FIELD INTENSITY: H  (Fmm+NI)/L = 0 +++++ MENU  REG  A...B  REG  a...e  1st....01...  ....11........ .......02..........12... L .. .......03..........13... H .. .......04..........14... I .. .......05..........15.. FMM . 2nd....06... N ....16........ .......07..........17........ .......08..........18........ .......09..........19........ .......10..........20........ User will see: [font=courier]  ^L ^H ^I FMM> A b .c ..d E second menu (pressing I) <N A .B C D E (The dot is just to align here in my post) In real HP code, as we have just 12 characters in display and 15 per line of program, I can use : instead of space to separate some variables. Bellow, I copy just the appearance of menus. See how I tried to keep each variable attached to one register for all equations.  B A R ^FMM u ^L A R uR u  ^H R uR  ^L ^H ^I FMM> <N Next post the implementation of some of these equations. ARTUR MARIO JUNIOR BRAZIL 

06222019, 07:31 PM
(This post was last modified: 06222019 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 AE or ae, 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 

06222019, 09:59 PM
(This post was last modified: 06222019 10:18 PM by Artur  Brasil.)
Post: #39




RE: HP 41  branching to local label and return stack
Now, the second equation: permeability: (u + uo.ur)  B/H = 0
Variables versus registers: 01  u; 02  B; 13  h; 04  R; 05  ur; uo is constant  reg 45 We will need to make XOR(u; ur; B) H <> 0 048 LBL 02 ........ second function 049 "PML" 050 ASTO X 051 CLA ............ here I need the u character. It will cause a disturbe in X register 052 12 053 XTOA 054 "> B ^H R " 055 X<>Y ........ I need to restore X register with function name for SOLVE. 056 XEQ "SFT1" 057 CLA ............... also no second menu 058 XEQ "SFT2" 059 1 .................. now, as we don't have to check result of some operation, I can 060 5 .................. use the registers numbers instead of values and call XORR (by registers) 061 2 .................. u; ur; B 062 RCL 44 ......... and the register number for variable solving 063 XEQ "XORR" 064 X=0? 065 GTO 11 ....... if XOR fails... 066 RCL 13 ...... if variables are ok, finally corrects the H variable 067 X=0? 068 1 069 STO 13 070 XEQ "SFT3" ..... everything ok, let's solve 071 GTO 02 .... once done, go back to function 072 LBL 11 .... for treat errors 073 "ZERE " 074 12 ..... again the u character ... 075 XTOA 076 ">*" 077 XTOA 078 ">R:B" 079 XEQ "SFT4" ... just show a message 080 GTO 02 .... go back to function 081 LBL "PML" ...... the function itself 082 STO IND 44 .... always save IND 44 083 RCL 05 084 RCL 45 085 * 086 RCL 01 087 + 088 RCL 02 089 RCL 13 090 / 091  092 RTN ARTUR MARIO JUNIOR BRAZIL 

06222019, 11:00 PM
Post: #40




RE: HP 41  branching to local label and return stack
The third equation is like others I post. Just a small difference in test.
R  L/(u+uo.ur).A = 0 We can't have both u and ur at same time. So, we must use another function to make the XOR: XOR2, which tests just 2 values in stack (x,y) (in LOGIC program you will find others functions XOR3, XOR4, X#0?L (is X different of zero? Returning 1 or 0), X=0?L Well, let's put the fourth equation: H  (Fmm+NI)/L = 0 XOR(FMM; N*I) L <> 0 LBL 04 "IND" ASTO X "^L^HÎ^FMM" XEQ "SFT1" "N" ............. here the second menu  very easy! XEQ "SFT2" RCL 15 RCL 06 RCL 14 * XEQ "XOR2" X=0? GTO 11 RCL 12 X=0? 1 STO 12 XEQ "SFT3" GTO 04 LBL 11 "ZERE FMM:N*I" XEQ "SFT4" GTO 04 LBL "IND" no finished ... ARTUR MARIO JUNIOR BRAZIL 

« Next Oldest  Next Newest »

User(s) browsing this thread: Schraf, 2 Guest(s)