▼
Posts: 1,216
Threads: 75
Joined: Jun 2011
Here's my next program for the WP34s: a complete triangle solver. :-)
http://www.hpmuseum.org/guest/fhub/trigon.zip
Have fun,
Franz
PS. I've also uploaded my prime-factorization program because someone asked for something like this in an other thread:
http://www.hpmuseum.org/guest/fhub/pf.zip
Edited: 28 Aug 2011, 10:50 a.m.
▼
Posts: 3,283
Threads: 104
Joined: Jul 2005
Thanks Franz!
I've had a short look at PF and I assume there is a bug or at least something I do not really understand. Here is the code for discussion:
/*
Prim-Faktor-Zerlegung (Prime Factorization)
Input: X:n (positive integer)
Output: X:pf1 [R/S] pf2 [R/S] ... [R/S] 0 (L:n)
Used: XYZT, IK
*/
001 LBL'PF'
002 INT?
003 x<1?
004 RTN
005 STO K
006 2
007 RCL Y
008 [sqrt]
009 IP
010 STO I
011 DROP
012 x>? I
013 SKIP 11
014 [cmplx]ENTER
015 RMDR
016 x=0?
017 SKIP 03
018 DROP
019 NEXTP
020 BACK 08
021 DROP
022 STOP
023 STO/ Y
024 BACK 17
025 DROP
026 STOP
027 CLSTK
028 x[<->] K
029 [times]
030 RTN
Line 13 (SKIP 11) seems to skip to line 24 (BACK 17). Maybe I haven't fully understood the algorithm but this looks a bit strange.
---
Edit: I'm not good at counting. :-( SKIP takes the number of steps to skip. I was stopping on the 11th step.
Skipping more then a few steps may save labels but does not improve readability of the program. Have you considered using the preprocessor features (symbolic labels)?
---
I haven't yet looked at the triangle solver.
Edited: 28 Aug 2011, 11:28 a.m. after one or more responses were posted
▼
Posts: 1,216
Threads: 75
Joined: Jun 2011
Quote:
Line 13 (SKIP 11) seems to skip to line 24 (BACK 17). Maybe I haven't fully understood the algorithm but this looks a bit strange.
Count again, Marcus! ;-)
In fact it jumps to line 25 ...
Edited: 28 Aug 2011, 11:24 a.m.
▼
Posts: 3,283
Threads: 104
Joined: Jul 2005
Shame on me. (See above).
Posts: 101
Threads: 11
Joined: Jun 2011
I'm new to the WP34s myself, and never worked with a 41C on which this one is based, but, wouldn't SKIP 11 skip the next 11 lines, and thus end up at 025 DROP?
▼
Posts: 1,216
Threads: 75
Joined: Jun 2011
Quote:
I'm new to the WP34s myself, and never worked with a 41C on which this one is based, but, wouldn't SKIP 11 skip the next 11 lines, and thus end up at 025 DROP?
Yes, you're right of course.
I also don't like the concept of SKIP very much: BACK nn jumps back nn steps, but SKIP nn jumps forward nn+1 steps (skipping nn steps).
It's always a bit confusing when writing a program, and I would definitely have prefered a combination BACK/FWD instead of BACK/SKIP.
▼
Posts: 653
Threads: 26
Joined: Aug 2010
This could be overcome by a general relative jump command, similar to those in the '67/97 or 34C (yet only backwards). While BACK nn in fact works like a "jump back nn lines", just as in the mentioned earlier models, SKIP nn in fact means "jump forward nn+1 lines".
A relative jump could handle both cases it (and only if) it could handle both positive and negative arguments. This has been discussed earlier regarding the current SDL and SDR commands which also would become much more useful if they were replaced by one common command which was able to handle positive and negative arguments. Pauli explained why this is currently not implemented, but maybe the benefits of a common relative jump command may help finding a solution. ;-)
If this is not possible SKIP could be replaced by another command that simply does the same as SKIP nn+1, which might be slightly less confusing. But I could also live without that. ;-)
Dieter
▼
Posts: 1,216
Threads: 75
Joined: Jun 2011
Quote:
If this is not possible SKIP could be replaced by another command that simply does the same as SKIP nn+1, which might be slightly less confusing.
Yes, that's exactly what I meant with FWD nn (instead of SKIP), jumping nn steps forward (as BACK nn does backward).
Posts: 3,229
Threads: 42
Joined: Jul 2006
Why all the problems with SKIP and BACK? SKIP nn skips the next nn steps. BACK nn goes back nn steps.
If we called the SKIP command FWD or FORWARD then it would operate differently but it isn't. It is called SKIP.
These commands have a bit of a sordid history. Originally included for internal xrom programming only but they turned out to be a useful way to reduce the step count so they were pushed mainstream. Now that we've lots of program steps in flash they are less relevant but still useful enough to include I think.
Finally, if you don't like them just use GTO/LBL instead. Nobody is forcing anyone to use these. They make debugging and altering programs more difficult, they take more keystrokes to enter and they don't necessarily have a speed advantage over LBL.
- Pauli
▼
Posts: 1,216
Threads: 75
Joined: Jun 2011
Quote:
Finally, if you don't like them just use GTO/LBL instead.
1) I didn't talk to or with _you_
2) I didn't criticize anything but just expressed my opinion
3) I guess (and hope) that saying one's opinion is still allowed here, isn't it?
Franz
▼
Posts: 3,229
Threads: 42
Joined: Jul 2006
Grow up.
None of what I said was directed at you, it was a public response in a public forum.
- Pauli
Posts: 653
Threads: 26
Joined: Aug 2010
Quote:
Line 13 (SKIP 11) seems to skip to line 24 (BACK 17). Maybe I haven't fully understood the algorithm but this looks a bit strange.
SKIP 11 means that the next 11 lines are skipped and the program continues with the 12th, i.e. line 13 + 12 = 25. ;-)
Dieter
Posts: 1,216
Threads: 75
Joined: Jun 2011
Quote:
Skipping more then a few steps may save labels but does not improve readability of the program. Have you considered using the preprocessor features (symbolic labels)?
Well, the preprocessor doesn't run here with my old TinyPerl, and I definitely don't want to install a 80MB package for just one little Perl script!
(BTW, since you've removed RCLS/STOS A again, also Neil's assembler isn't uptodate anymore - it gives an error message for these 2 commands.)
And for 'readability': my triangle program you couldn't even 'read' (i.e. understand) WITH symbolic labels. ;-)
Edited: 28 Aug 2011, 11:44 a.m.
▼
Posts: 3,283
Threads: 104
Joined: Jul 2005
Franz, try the .exe version. It does not need Perl to be installed.
▼
Posts: 1,216
Threads: 75
Joined: Jun 2011
Quote:
Franz, try the .exe version. It does not need Perl to be installed.
I've tried it already:
1) horribly slow
2) creates BIG temporary files in Windows\temp folder and doesn't delete it at the end, so either I have to remove them manually or this folder grows with each run
Conclusion: thanks, that's not a tool I would like! ;-)
▼
Posts: 3,283
Threads: 104
Joined: Jul 2005
Quote:
I've tried it already:
1) horribly slow
Only on the first run.
Quote:
2) creates BIG temporary files in Windows\temp folder and doesn't delete it at the end, so either I have to remove them manually or this folder grows with each run
That's why it is slow on the first run but not on subsequent executions. Temp should get cleared on a reboot by Windows.
Posts: 255
Threads: 22
Joined: May 2011
Quote:
(BTW, since you've removed RCLS/STOS A again, also Neil's assembler isn't uptodate anymore - it gives an error message for these 2 commands.)
I presume you are not using SVN then. I am suspecting that you may be manually downloading the assembler script from the Source Forge website. If so, then you are likely not also copying the wp34s.op table that is there as well (same directory).
While the embedded table within the assembler is not updated on every twitch and whim of the rest of the project, the ./trunk/tools/wp34s.op table is essentially (semi)automatically updated during the build process. The assembler searches for the wp34s.op op-code table in the following order: 1) where you said it was using the -op command line switch, 2) the directory you are running the script from, 3) where the script itself is located, and finally, if none of the previous are true, 4) the assembler uses its internal table as a last resort fall-back.
When you run the assembler, it will report which table it used -- both its revision number (if known), and its location (something about "internal" if it could find one).
It is possible that the assembler reports 2 warnings (not errors!) about duplicate op-codes with regard to STOS A/RCLS A. Regardless, the 2 warnings it reports are harmless and can be ignored -- unless you happen to be trying to use STOS A and/or RCLS A. Depending on which revision of the calculator design you are using, the STOS A and RCLS A instructions may or may not exist.
With respect to the EXE versions, they were fully documented to behave as you state (slow -- on the 1st decompression run, and large -- being about 15M footprint). Additionally, the reasons for this were also documented. So no surprises there.
None the less, the ability to use "JMP DoThatThingAgain" instead of SKIP 78 or BACK 23 is a large benefit to self-documented, readable code (it will do a better job counting steps than the human as well!). The tool figures out these n+1 issues for SKIP and deals with them accordingly. Furthermore, if the JMP exceeds the dynamic range of the the SKIP/BACK instruction, the PP tool automatically promotes the branch instruction into a GTO instruction (inserting a LBL at the correct spot, only if required).
▼
Posts: 1,216
Threads: 75
Joined: Jun 2011
Quote:
I presume you are not using SVN then. I am suspecting that you may be manually downloading the assembler script from the Source Forge website. If so, then you are likely not also copying the wp34s.op table that is there as well (same directory).
Well, I'm indeed manually downloading both your assembler script AND the wp34s.op whenever one of them changes.
And I know that at the moment (SVN1535) it's working again - but I'm sure not for long time: at least when Pauli awakes again those assembler warnings will reappear ... ;-)
▼
Posts: 255
Threads: 22
Joined: May 2011
Quote:
I know that at the moment (SVN1535) it's working again
I would be somewhat surprised if the assembler stopped working. It was (is?) issuing the warning messages about duplicate op-codes because of an internal matter within the design team. But, as far as I am aware, it never produced illegal code or failed to assembler a source file** (at least in the last month or so). If you have a set of files that it is failing against, can you please share the details?
When the internal matter regarding STOS A/RCLS A is finalized, the assembler will be updated. Until then, you can safely ignore the warnings.
** Unless you were using the STOS A/RCLS A instruction -- and then it depended on which specific version of the calculator you were using -- and then it simply said you were using an illegal instruction (being STOS A and/or RCLS A).
▼
Posts: 1,216
Threads: 75
Joined: Jun 2011
Quote:
If you have a set of files that it is failing against, can you please share the details?
So far I didn't have any problems with your assembler - it works perfectly. And of course these STOS/RCLS warnings aren't your fault.
Quote:
When the internal matter regarding STOS A/RCLS A is finalized, ...
Well, this will be a never ending story I'm afraid. ;-)
▼
Posts: 255
Threads: 22
Joined: May 2011
Quote:
And of course these STOS/RCLS warnings aren't your fault
I prefer to think of these things as nobody's fault. They are part of an evolving architecture that has some pretty healthy debate happening behind the scenes.
(My tool has its share of issues as well. I am just luckier that they have mostly been caught in that behind the scene evolution. Pauli found a bit of a howler in the PP last week. It would not allow 1/x through unmolested -- to keep the theme going -- under certain circumstances.)
Quote:
Well, this will be a never ending story I'm afraid. ;-)
I, and more than a few others, hope not! However, this one will be resolved quite soon -- of that I am confident.
Posts: 274
Threads: 23
Joined: Sep 2007
Hi all,
My apologies if already discussed.
I understand that labels are just a waste of place and time in a program (at least when it is fully debugged and frozen).
But when you edit a program, labels are helpful because you don't have to keep track of the lines inserted or removed to know how far you have to jump.
When you remove a label, if not on purpose, you can bet that a GTO or an WEQ will fail soon or late. If the label is not there, you have chances not notice.
It is just my opinion, but you can have guessed that I don't like the SKIP and BACK commands with relative jumps, because you have to do maths when the calc can display the useful result directly.
In the contest of removing the labels, I would have preferred a JUMP command with an absolute line number (with same range as BACK and SKIP). (or GTOL for a GTO Line programmable)
Even better, having 2 more commands:
the first one SHRINK, non programmable, would convert the current program with labels to the form without labels (at least the numerical ones from the HP41C point of view).
The second one EXPAND, non programmable, doing the reverse, aka reinserting the labels.
The EXPANDed form would be (need to renumber the lines):
001 LBL'PF'
002 INT?
003 x<1?
004 RTN
005 STO K
006 2
LBL 03
007 RCL Y
008 [sqrt]
009 IP
010 STO I
011 DROP
LBL 02
012 x>? I
013 GTO 00
014 [cmplx]ENTER
015 RMDR
016 x=0?
017 GTO 01
018 DROP
019 NEXTP
020 GTO 02
LBL 01
021 DROP
022 STOP
023 STO/ Y
024 GTO 03
025 DROP
LBL 00
026 STOP
027 CLSTK
028 x[<->] K
029 [times]
030 RTN
The SHRINKed form:
001 LBL'PF'
002 INT?
003 x<1?
004 RTN
005 STO K
006 2
007 RCL Y
008 [sqrt]
009 IP
010 STO I
011 DROP
012 x>? I
013 GTOL 25
014 [cmplx]ENTER
015 RMDR
016 x=0?
017 GTOL 21
018 DROP
019 NEXTP
020 GTOL 12
021 DROP
022 STOP
023 STO/ Y
024 GTOL 7
025 DROP
026 STOP
027 CLSTK
028 x[<->] K
029 [times]
030 RTN
Patrice
▼
Posts: 255
Threads: 22
Joined: May 2011
Hi Patrice,
Have you looked at the off-line preprocessor for the assembler? If not, have a look at chapter 8 of the assembler document.
▼
Posts: 274
Threads: 23
Joined: Sep 2007
Is it an assembler program ?
In this case, apologize, I thought it is a 'FOCAL' user program.
Patrice
▼
Posts: 3,283
Threads: 104
Joined: Jul 2005
"Assembler" here is the same what "Focal" is for the 41C. It was Neil's decision to call his perl script neither translator nor compiler but assembler. The "assembly language" is just the keystroke programming model of WP 34S.
▼
Posts: 274
Threads: 23
Joined: Sep 2007
In my 30 years of computer programming experience, I have always heard of "assembler" or "assembly language" as being a more or less readable form of the language of the microprocessor.
Using the word "assembler" for the user keystroke programming language is quite unusual for me.
Patrice
Posts: 255
Threads: 22
Joined: May 2011
Quote:
Is it an assembler program ?
In this case, apologize, I thought it is a 'FOCAL' user program.
Sorry, I have only heard of FOCAL used in the context of the '41. I did not understand your comment until Marcus' note.
The assembler will do several things. Firstly, it will disassemble a binary image extracted from the user programmable spaces (ie: key-stroke programmable area) in either the calculator or the emulator. Secondly, it will take an ASCII source (either a previously disassembled one or one you have written using an editor) and create a binary image that can be loaded into the key-stroke programmable sections of either the calculator or the emulator.
Recently there was a new addition to the tool chain, that I am calling a preprocessor (or PP), that does some symbolic manipulation of the source. The output of the PP can be fed into the assembler. (The assembler can also be requested to spawn a PP job directly via a command line switch as well.)
Your comment about superfluous labels, JUMP instructions, counting, etc. is essentially exactly what the PP does.
Again, if you have not had a chance, read the WP34s_Assembler_Disassembler.pdf document in the WP 34S offering. It should answer many questions. Chapter 8 deals specifically with this topic.
Regards...
▼
Posts: 274
Threads: 23
Joined: Sep 2007
Quote:
Sorry, I have only heard of FOCAL used in the context of the '41.
Me too, this is why I writed 'FOCAL', would you have preferred "User Keystroke Programming Language" ?
My SHRINK and EXPAND commands were for the real thing, to help programming live.
Try to program and debug something without the help of a computer or a sheet of paper and you will see my point about the labels.
Quote:
WP34s_Assembler_Disassembler.pdf document in the WP 34S offering. It should answer many questions. Chapter 8 deals specifically with this topic.
Chapter 8 is named "Help" is it the right one ?
▼
Posts: 255
Threads: 22
Joined: May 2011
Quote:
Chapter 8 is named "Help" is it the right one ?
It is named "Help" in older versions. In the latest it is called "Symbolic Preprocessor". The latest version went online about 2 weeks ago. Look here.
I can't help you with the "live" programs. That is not my department. :-)
Posts: 1,216
Threads: 75
Joined: Jun 2011
Quote:
The EXPANDed form would be (need to renumber the lines):
...
Hey, what are you doing with my poor little program?
That's almost rape ... ;-)
▼
Posts: 274
Threads: 23
Joined: Sep 2007
Yes, I am a serial program raper :)
▼
Posts: 1,216
Threads: 75
Joined: Jun 2011
Quote:
Yes, I am a serial program raper :)
Well, better serial than parallel (at least in this case). :-)
▼
Posts: 274
Threads: 23
Joined: Sep 2007
Sometimes, parallel is good too.
By the way, do you think the program is read easier with absolute line numbers?
Patrice
▼
Posts: 1,216
Threads: 75
Joined: Jun 2011
Quote:
By the way, do you think the program is read easier with absolute line numbers?
You mean direct jumps to line numbers?
Yes, that would of course be (a bit) easier than all this counting for BACK or SKIP.
Posts: 101
Threads: 11
Joined: Jun 2011
I like the PF program, thanks! I like it especially as a learning experience of the WP34s commands.
Posts: 239
Threads: 55
Joined: Sep 2006
Hi,
Here is maybe a dumb question: how do you create an instruction like:
048 [alpha]'on:'
in your triangle program? I cannot see how I can add a special character like ':' and in this instruction.
Thanks,
Miguel
Edited: 29 Aug 2011, 6:12 p.m.
▼
Posts: 1,216
Threads: 75
Joined: Jun 2011
Sorry Miguel, but unfortunately I can't answer your question.
I'm not entering my programs directly on the emulator, I just write my programs in a texteditor, compile them and load them into the emulator.
Franz
Posts: 3,229
Threads: 42
Joined: Jul 2006
See page 9 of the manual for the alpha to keyboard map.
Due to some internal limitations, the various alpha catalogues are not available during the three character alpha entry sequences. This means that you will have to enter the ':' character as a single character alpha.
The assembler accepts more than can be entered from the keyboard and the execution engine doesn't care. This applies not only to alpha triples but to labels as well.
- Pauli
▼
Posts: 239
Threads: 55
Joined: Sep 2006
Ah, Domage!
I thought as much, having read the "interactive.html" document.
Thanks you both and regards,
Miguel
|