My 1st HP-41 program. Suggestions?
|
10-19-2023, 12:49 AM
Post: #1
|
|||
|
|||
My 1st HP-41 program. Suggestions?
After having spent some time typing in simple programs suggested from "HP-41C
STANDARD APPLICATIONS" as suggested by Sylvain I decided to write a guess the number program as I have done this on almost every new system I have programmed since the mid 1980s. The random number generator is from the Games book. I did add a seed function that uses TIME. The method of displaying prompts was copied from the Guess the word program in the Standard Apps manual. I'm curious how others might optimize this program. I just implemented one small change as noted in the listing below. The RTN and END were removed from SEED so it drops through to RNDM. This also allows removing one line from GNUM as well. I tried to keep the random number in Y by using strategically placed RDROPs. This works but seems messy. It is also not ideal on the DM41X as you can see the random number. I guess the number could be stored in R02 and an indirect Y used instead. Code:
Code:
|
|||
10-19-2023, 01:27 AM
Post: #2
|
|||
|
|||
RE: My 1st HP-41 program. Suggestions?
What is RDROP?
<0|ɸ|0> -Joe- |
|||
10-19-2023, 01:32 AM
Post: #3
|
|||
|
|||
RE: My 1st HP-41 program. Suggestions?
All My Articles & other Materials here: Valentin Albillo's HP Collection |
|||
10-19-2023, 03:53 AM
Post: #4
|
|||
|
|||
RE: My 1st HP-41 program. Suggestions?
(10-19-2023 12:49 AM)Jeff_Birt Wrote: My 1st HP-41 program. Suggestions? There are a number of optimizations which could be made but for a first program it's quite acceptable. The largest optimization would be this: The 15 lines in your original code highlighted in bold red below:
"Guess 1-10" PROMPT ; Type in # then press R/S X=Y? GTO 03 ; Correct guess handler X>Y? GTO 02 ; X>Y handler "TOO SMALL" ; **X<Y handler AVIEW PSE PSE RDROP ; Keep Rand # in Y GTO 01 LBL 02 ; **X>Y handler "TOO BIG" AVIEW PSE PSE RDROP ; Keep Rand # in Y GTO 01 LBL 03 ; **Correct handler [...]
X>Y? "TOO BIG" AVIEW PSE PSE RDROP GTO 01 Hope it helps. V. All My Articles & other Materials here: Valentin Albillo's HP Collection |
|||
10-19-2023, 12:12 PM
Post: #5
|
|||
|
|||
RE: My 1st HP-41 program. Suggestions? | |||
10-19-2023, 12:17 PM
Post: #6
|
|||
|
|||
RE: My 1st HP-41 program. Suggestions?
(10-19-2023 03:53 AM)Valentin Albillo Wrote: There are a number of optimizations which could be made but for a first program it's quite acceptable. The largest optimization would be this: Yes, thanks. This was the sort of feedback I was hoping for. Since ALPHA is not displayed until the AWIEW it does make sense to do things as you suggest. |
|||
10-19-2023, 03:59 PM
(This post was last modified: 10-19-2023 04:15 PM by Peet.)
Post: #7
|
|||
|
|||
RE: My 1st HP-41 program. Suggestions?
(10-19-2023 12:12 PM)Jeff_Birt Wrote: When looking at the 'R down arrow' (Roll Down) key I was trying to think of how to express that in a text editor and the Forth word DROP came to mind and thus RDROP was born Press and hold the key to see the name RDN on the 41. Drop isn't the best choise because the stack rotates on RPN and not "drops" like RPL (DROP is more similar to CLX). By the way, one of my first programs for the 41 over 40 years ago was also "guess a number" (HiLo), but my code was less optimized. My calculators - former: CBM PR100, HP41CV, HP11C, HP28S - current: HP48G, HP35S, Prime, DM41X, DM42, HP12C |
|||
10-20-2023, 12:00 AM
Post: #8
|
|||
|
|||
RE: My 1st HP-41 program. Suggestions?
(10-19-2023 12:17 PM)Jeff_Birt Wrote: Yes, thanks. This was the sort of feedback I was hoping for. You're welcome. Since you liked my suggestion, here's another one for you: Your 6-line code in bold red below ...
INT LBL 01 RCL 01 1 + STO 01 ; Increment the guess counter RDROP ; Keep Rand # in Y "Guess 1-10" [...]
ISG 01 LBL 01 Regards. V. All My Articles & other Materials here: Valentin Albillo's HP Collection |
|||
10-20-2023, 02:21 AM
Post: #9
|
|||
|
|||
RE: My 1st HP-41 program. Suggestions?
(10-20-2023 12:00 AM)Valentin Albillo Wrote: [snip] Nice one Valentin! Double use of the same label is an effective NOP here, typically not the case. At least this portion will not be further optimized... --Bob Prosperi |
|||
10-20-2023, 03:16 AM
Post: #10
|
|||
|
|||
RE: My 1st HP-41 program. Suggestions?
(10-20-2023 02:21 AM)rprosperi Wrote:(10-20-2023 12:00 AM)Valentin Albillo Wrote: ... can be replaced by this 3-line codeNice one Valentin! Double use of the same label is an effective NOP here, typically not the case. Thanks for your appreciation, Bob. Re-using LBL 01 is ideal, as it's a 1-byte instruction which here it's just a never-executed placeholder and it can't be reached from anywhere in the program, whether directly or indirectly. And yes, this portion can't be optimized any further ... Best regards. V. All My Articles & other Materials here: Valentin Albillo's HP Collection |
|||
10-20-2023, 12:37 PM
Post: #11
|
|||
|
|||
RE: My 1st HP-41 program. Suggestions?
(10-20-2023 12:00 AM)Valentin Albillo Wrote: ... can be replaced by this 3-line code Thanks. I had briefly looked at ISG (DSE) as they are the only built in INC/DEC type of commands. I was not sure how they would respond if the register was not set up entirely as you would for the proper use of the command. I seem to recall the manual said that if a step size was not specified, or zero was given than a step size of 1 would be used. The reuse of LBL 01 is clever. I am not certain how the calculator parses a program. Given that this trick works though it must parse form the top and the first instance of LBL 01 is acted on. It leads me to wonder if the program is parsed top to bottom each time a local label is used or if the first time a label is encounter its address is stored somewhere and accessed by index. More reading to do. Funny how much I have learned over the years from this simple little program. |
|||
10-20-2023, 10:05 PM
Post: #12
|
|||
|
|||
RE: My 1st HP-41 program. Suggestions?
(10-20-2023 12:37 PM)Jeff_Birt Wrote: The reuse of LBL 01 is clever. I am not certain how the calculator parses a program. Given that this trick works though it must parse form the top and the first instance of LBL 01 is acted on. It leads me to wonder if the program is parsed top to bottom each time a local label is used or if the first time a label is encounter its address is stored somewhere and accessed by index. More reading to do. The calculator scans the source code, searching for the given local label, from the position of the program counter (containing a GTO ou EXQ instruction) down to the first occurrence of the label. Thibault - not collector but in love with the few HP models I own - Also musician : http://walruspark.co |
|||
10-21-2023, 12:51 AM
Post: #13
|
|||
|
|||
RE: My 1st HP-41 program. Suggestions?
Thanks. I thought of a rather contrived example to demonstrate how this works. The code has two global label entry points LBL 'E1' and LBL 'E2', each with an LBL 01 two lines later. XEQ 'E1' and XEQ 'E2' and see where it exits.
Code:
|
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)