Post Reply 
EXC/ x<>Rn for stack efficiency
06-14-2017, 10:36 AM (This post was last modified: 06-14-2017 11:01 AM by Paul Dale.)
Post: #13
RE: EXC/ x<>Rn for stack efficiency
Dieter is correct, the best way to do this is to understand the algorithm and recode it. RPN programs should almost always be shorter than AOS ones.

Since you want some code, this sequence will swap X and register 1 using register 0 and preserving the rest of the stack:

Code:
01  X<>Y
02  STO 0
03  CLx
04  RCL 1
05  X<>Y
06  STO 1
07  CLx
08  RCL 0
09  X<>Y


To avoid using the register, Last X can be used instead but this requires the arithmetic operation in step 2 to be undone in step 8 without loss (multiplication and division would also work as a pair in the same manner). This code swaps X with register 0 and leaves the rest of the stack intact:

Code:
01  X<>Y
02  +
03  RCL 0
04  X<>Y
05  STO 0
06  CLx
07  LAST X
08  STO- 0
09  X<>Y

Both are for the HP-25. Using 20% of the program memory to swap X with a register seems a little wasteful.


Pauli
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: EXC/ x<>Rn for stack efficiency - Paul Dale - 06-14-2017 10:36 AM



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