The HP Calculator Specialists

Publicado el por JGD
# Programming the HP41CL - some comments.

Programming the HP41CL - some comments.

While looking at the many programs found in the Solution Manuals or the modules, in many cases I find that the data entry to the program is too formatted and not flexible enough. In my opinion, what is really needed is a clear register usage, so that the user can put the correct data into the right registers beforehand - no need to go through all of the data in order to start the program again.

One typical case is the cashflow-related programs. If we agree that the 0 register is now, and register 1 = period 1, and so on, things can get very easy for data entry. You just need to define how many years you’re using, store that in a register outside of the possible year length scope, and then enter all the year data in the order you want, correcting it as many times you want, checking the contents whenever you want, etc. No need for cumbersome data entry procedures.

I would like to be able to apply the same logic to matrix entry, but here the knowledge of how a matrix is stored is much more involved. There, the example to follow is the HP15c user mode matrix data entry for serial entry, and the register 0 and 1 use to fix the pointer in the right cell.

Let’s show it with a couple of examples that I much prefer to the options found in the financial pac or in the financial solutions book: Net Present Value (NPV) and Internal Return Rate (IRR)

Lets agree that the maximum cash-flow length is 20 years (periods). This is OK for most investment projects. This assumption is important, since it is a “hard” limit in the program. If you feel that 10 years is enough, you can modify the program accordingly and be able to run it with a lower “SIZE” arrangement. However, this is not a concern anymore for us CL users.

We will focus on the NPV function, to make it as simple as we can, and forget about IRR. We will use the SOLVE function found in the Advantage pac to find it.

We use register 21 to store the number of periods to use, in order to make the loop shorter; we will use register 22 for the countdown, as the indirect register used in HP15c and others. And the registers 0 to 20 are self explained with regard to periods.

1 LBL VAN

2 1e2 Change X to %

3 /

4 1

5 +

6 1/X Prepare 1/(1+X)

7 ENTER^ Load the stack

8 ENTER^

9 ENTER^

10 RCL 21 Recall number of years

11 STO 22 Store in the indirect register

12 CLX Clear X

13 0 Enable stack lift to start the loop

14 LBL VAN1 Loop

15 RCL IND 22 Recal Year n cashflow

16 + add to previous value

17 * multiply times 1/(1+X)

18 DSE 22 Decrement register and check if zero

19 GTO VAN1 if not zero, do it again

20 RCL 00 Recall initial flow

21 + Add

22 RTN Return so it can be used as a

1 | LBL VAN | |

2 | 1e2 | Change X to % |

3 | / | |

4 | 1 | |

5 | + | |

6 | 1/X | Prepare 1/(1+X) |

7 | ENTER^ | Load the stack |

8 | ENTER^ | |

9 | ENTER^ | |

10 | RCL 21 | Recall number of years |

11 | STO 22 | Store in the indirect register |

12 | CLX | Clear X |

13 | 0 | Enable stack lift to start the loop |

14 | LBL VAN1 | Loop |

15 | RCL IND 22 | Recal Year n cashflow |

16 | + | add to previous value |

17 | * | multiply times 1/(1+X) |

18 | DSE 22 | Decrement register and check if zero |

19 | GTO VAN1 | if not zero, do it again |

20 | RCL 00 | Recall initial flow |

21 | + | Add |

22 | RTN | Return so it can be used as a subroutine |

Now, the IRR is extremely easy, based on the SOLVE capability of the Advantage Pac:

1 | LBL TIR |

2 | VAN |

3 | SOLVE |

4 | END |

Comentarios: 0

Más sobre:
HP41cl
Solo los usuarios registrados pueden poner comentarios.

Identificarse y añadir comentario
Regístrese ahora