Post Reply 
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:

// To seed the RNG
LBL "SEED"
TIME
FRC
STO 00
RTN             ; Can leave out to drop through to RNDM
                   ; Also remove END                                      

// Method #1
LBL "RNDM"
RCL 00
9821
*
.211327
+
FRC
STO 00
RTN

Code:

//Guess the number game
LBL "GNUM"
0               ; Init # of guesses
STO 01          ; REG01 stores # of guesses
XEQ "SEED"      ; Seed RNDM then XEQ RNDM
//XEQ RNDM        ; Random # < 1, can leave out w/modified SEED
10
*
1
+               ; convert to value 1-10
INT
LBL 01
RCL 01
1
+
STO 01          ; Increment the guess counter
RDROP           ; Keep Rand # in Y
"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
RCL 01
ARCL X
"|- GUESSES"
AVIEW 
RTN
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
My 1st HP-41 program. Suggestions? - Jeff_Birt - 10-19-2023 12:49 AM



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