The Museum of HP Calculators

HP Forum Archive 16

[ Return to Index | Top of Index ]

HP-41C Commands to RPL
Message #1 Posted by Gerry Schultz (Los Angeles) on 6 Nov 2006, 9:36 p.m.

I have a quick question. As a part of working on the Prime numbers Program discussed early last week, is there a source somewhere that can demonstrate HP-41C commands translated to HPL commands? I'm specifically trying to duplicate commpand such as:

ST+ 00 RCL IND 01 STO Z ISG 01 ST- 01 ST* IND 01

So I'm trying to duplicate indirect storage, increment registers (which could be duplicated with loop structures), and stack arithmetic with indirect storage. Finally, how do you duplicate register T's behavior of duplication when the stack drops?

Thanks,

Gerry

      
Re: HP-41C Commands to RPL
Message #2 Posted by James M. Prange (Michigan) on 6 Nov 2006, 10:13 p.m.,
in response to message #1 by Gerry Schultz (Los Angeles)

Suggestion: Use [pre] and [/pre] around code when you post it. See the advanced formatting techniques.

I expect that your code was meant to look like:

ST+ 00
RCL IND 01
STO Z
ISG 01
ST- 01
ST* IND 01

Regards,
James

      
Re: HP-41C Commands to RPL
Message #3 Posted by James M. Prange (Michigan) on 7 Nov 2006, 2:12 a.m.,
in response to message #1 by Gerry Schultz (Los Angeles)

On an RPL model, storage is implemented with named variables, either local or global.

With the variable-depth stack of RPL, you don't really have to use variables to store values for later use if you don't want to; you could leave them on the stack and use stack manipulation commands to copy or move them to where they're needed. That said, it's often easier to use local variables.

Any variable, either local or global, can be incremented with the INCR command or decremented with the DECR command.

Of course values can be incremented with loops too. Within any loop, you can increment a variable with the INCR command, or a value on the stack just by adding 1 to it.

With a FOR loop, the loop index is implemented as a local variable, with the name specified by the user, and accessible by name within the loop. A FOR...NEXT loop always increments the index, and with a FOR...STEP loop, the index is increased or decreased by a user-specified value. START loops are similar, but the loop index isn't accessible with UserRPL.

I'm not certain what you mean by "stack arithmetic with indirect storage", but the RPL models do include the commands STO+, STO-, STO*, and STO/, which work with any variable, local or global. For example, to subtract 1 from a variable's value, use 'name' 1 STO-, or to subtract the variable's value from 1, use 1 'name' STO-.

Offhand, I don't see any way to really duplicate the downward replication of the T register. You could store a value in a variable (again, local or global) which can furnish an endless supply of the value simply by calling the variable by name.

Other than that, DEPTH PICK will always copy the topmost stack level down to level 1. If you want it on level 2 instead, then use DEPTH PICK SWAP, or for level 3, DEPTH PICK ROT ROT, or on a 49 series, you can replace ROT ROT with UNROT, or for level 4, DEPTH PICK 4 ROLLD, or for level 5, DEPTH PICK 5 ROLLD, and so on.

Or you could "pre-load" the stack with several copies of an object. For example, to put 20 copies of the number 5 on the stack, you could do 1 20 START 5 NEXT. On the 49 series, you could use the NDUPN command instead, for example, 5 20 NDUPN DROP.

Which RPL model are you using?

Regards,
James

            
Re: HP-41C Commands to RPL
Message #4 Posted by James M. Prange (Michigan) on 7 Nov 2006, 2:24 a.m.,
in response to message #3 by James M. Prange (Michigan)

Out of curiosity, I just checked something. STEP will accept a value of 0, making an "endless" FOR...STEP or START...STEP loop. Of course, depending on what else is in the loop, the calculator may eventually run out of memory, or it can be ended with with CANCEL or ATTN keypress.

Regards,
James

                  
Re: HP-41C Commands to RPL
Message #5 Posted by Gerry Schultz (Los Angeles) on 7 Nov 2006, 2:32 p.m.,
in response to message #4 by James M. Prange (Michigan)

James:

Thanks for the response. I own a 48GX, 49g, 49g+ and a 50g. I want to convert the 41C Prime Number program to RPL and I was thinking the first step is to convert the 41C commands to RPL. This Prime Number program isn't all that complex, it's just convoluted to keep it short and fast but makes it hard (for me anyway) to analyze.

I just had a thought. Do any of the 41C emulators allow you to single step through a program while monitoring the stack as well as data registers? Right now I'm doing this by hand and it's a pain in the butt. But if a 41 emulator will display the stack and critical registers on a PC screen, then I can watch how the program works without killing more trees.

Thanks,

Gerry


[ Return to Index | Top of Index ]

Go back to the main exhibit hall