RPN-like STO/RCL on RPL calculator - Printable Version +- HP Forums (https://archived.hpcalc.org/museumforum) +-- Forum: HP Museum Forums (https://archived.hpcalc.org/museumforum/forum-1.html) +--- Forum: Old HP Forum Archives (https://archived.hpcalc.org/museumforum/forum-2.html) +--- Thread: RPN-like STO/RCL on RPL calculator (/thread-159432.html) RPN-like STO/RCL on RPL calculator - David Hayden - 11-13-2009 One thing I missed when moving from a 41CV to a 50G was the ease of storing and recalling variables. To store 123 in register 01 on the 41CV you just type "123 STO 01" (6 keystrokes). You can even use the top two rows of keys as shortcuts for registers 01-10 so the keystroke count is really 5 (1 2 3 STO SIGMA+). On the 50G, the variables are named and they have to be quoted, so the same thing would be something like 1 2 3 ' alpha R 0 1 STO - a whopping 9 keys. Now it's true that once you've defined a variable, it's accessible from the VAR menu with one key to recall it and 2 keys to store into it (LS followed by the key for the variable), but if you aren't actually IN the VAR menu, then you add 3 keystrokes to get to the VAR menu and back (VAR to get there, LS (hold) PREV to get back). To get around this, I created the following UserRPL programs STOn and RCLn. If you type "123 1 STOn" then it stores 123 into variable R1. Similarly "1 RCLn" will recall variable R1. If you type "123 'myvar' STOn" then it behaves just like STO, storing 123 in 'myvar'. More specifically, STOn/RCLn examine the value on level 1 of the stack. If it's a positive integer or a real number greater than zero with no fractional part, then STOn/RCLn will store/recall the variable Rn where "n" is the value on level 1. If there are fewer than 2 values on the stack or if the conditions above aren't met, then STOn/RCLn just call STO/RCL. With this behavior, you can assign the programs to the STO and RCL keys and your calculator will behave the way I want it to... :) Here are the programs: ```« @ STOn/RCLn RPN-like STO and RCL functions @ If the stack depth is 2 or more @ and level 1 is a positive integer or real @ with no fractional part, then store @ level 2 in variable Rn where "n" is the @ integer on level 1. Pop 2 levels @ @ If the conditions aren't as mentioned above, then @ call STO. C-like pseudo code is: @ if (depth > 1 && @ (type == 0. && fractionalPart == 0 && value >= 0|| @ type == 028&& value >= 0) { @ construct string "Rn"; @ convert it to an identifier @ store it. @ } else { @ STO @ } @ The pseudo code relies on C's short-circuit @ "and" operation. I'll do short-circuit AND @ like this (for 'A == 0 && B == 1"): @ A 0 == @ IF DUP THEN @ B 1 == AND @ END DEPTH 1 > IF DUP THEN OVER TYPE 0. == @ Is it REAL? IF DUP THEN 3. PICK FP 0. == AND 3. PICK 0. Š AND END IF DUP NOT THEN DROP OVER TYPE 28. == IF DUP THEN 3. PICK 0 Š AND END END END AND IF THEN RI STR "'R" SWAP + "'" + OBJ END STO » 'STOn' STO @ Here is RCLn « DEPTH 0. > IF DUP THEN OVER TYPE 0. == @ Is it REAL? IF DUP THEN 3. PICK FP 0. == AND 3. PICK 0. Š AND END IF DUP NOT THEN DROP OVER TYPE 28. == IF DUP THEN 3. PICK 0 Š AND END END END AND IF THEN RI STR "'R" SWAP + "'" + OBJ END RCL » 'RCLn' STO ``` Re: RPN-like STO/RCL on RPL calculator - Stuart Sprott - 11-14-2009 David, I have done much the same thing. I created a matrix called "Regs", it is a 32*1 matrix. That means there are 32 registers. You can make it whatever you like. When created it was full of zeros. Then I wrote two programs, STOi and RCLi. If you want to say store 2.5 into register 6, then key in 2.5 then enter 6 and run program STOi. If you want to recall the number in register 9, enter 9 press RCLi. These two programs are assigned to to keys I normally dont use. The two programs are listed below. STOi << > a b << Regs b a PUT 'Regs' STO >> >> RCLi << > a << Regs a GET >> >> Re: RPN-like STO/RCL on RPL calculator - Gerson W. Barbosa - 11-14-2009 A similar approach, from the HP-28S Owner's Manual, page 300: -------------------------------------------------------------------------------- Registers Versus Variables Fixed-stack calculators can deal efficiently only with real, floating-point numbers for which the fixed, seven-byte register structure of the stack and numbered data register memory is suitable (the HP-41 introduced a primitive alpha data object constrained to seven-byte format). The HP-28S replaces numbered data registers with named variables. Variables, in addition to having a flexible structure so that they can accomodate different object types, have names that can help you remember their contents more readily than can register numbers. If you want to duplicate numbered registers on the HP-28S, you can use a vector: `{ 50 } 0 CON 'REG' STO` creates a vector with 50 elements initialized to 0; `<< 'REG' SWAP GET >> 'NRCL' STO` creates a program NRCL that recalls the nth element from the vector, where n is a number in level 1; `<< 'REG' SWAP ROT PUT >> 'NSTO' STO ` creates the analogous store program NSTO. -------------------------------------------------------------------------------- Re: RPN-like STO/RCL on RPL calculator - David Hayden - 11-14-2009 Quote: I have done much the same thing. I created a matrix called "Regs", it is a 32*1 matrix. That means there are 32 registers. You can make it whatever you like. When created it was full of zeros. Stuart, I considered this approach, but the values in a matrix must all be the same type, so you can't, for example, store a list in one position and a program in another. I could have gotten around this by using a list, but I thought that would be somewhat slower if the list was very large. Also, if you wanted to store in R100-R120, you'd have to create items 1-99 in the list anyway. Quote: Then I wrote two programs, STOi and RCLi. ... These two programs are assigned to to keys I normally don't use. I did something similar in an earlier version, but then it occurred to me that with a little extra code, the program could determine if it should do its thing or just call STO/RCL. Then I could assign it to the STO and RCL keys Obviously a lot of the code is in this functionality, so removing it will greatly reduce the size of the program. Re: RPN-like STO/RCL on RPL calculator - Paul Dale - 11-14-2009 How about a sysRPL version that takes the number as a postfix argument to STO & RCL? I.e. 123 STO 0 will store 123 in register 0. Then allow programs and algebraics after the STO & RCL :-) - Pauli