Post Reply 
Example Program to calculate Factorial
01-31-2018, 02:59 PM
Post: #2
RE: Example Program to calculate Factorial
Great! This is also the Example used by Wikipedia for the HP-16C. That example has only nine steps, though it does not employ the validity check at the start, and the 16C has the DSZ (decrement, skip if zero) instruction that the 11C does not. It should be possible to make something out of the DSE instruction though. still i like about your program that it is easier to overlook which is good for starters, as the wikipedia example is heavily optimized and not as easy to understand on first look.

Maybe one could extend the Example on to "how to save space" or similar if the second program was added.

this is it:
Code:
001 LBL F   43,22, F  Define label F (mnemonic for "factorial")
002 x<>I    42 22     Store x in register I
003 1       1         Store 1 in x
004 LBL 0   43,22, 0  Define label 0
005 RCL I   45 32     Recall register I into x
006 ×       20        Multiply x and y
007 DSZ     43 23     Decrement register I and if not zero ...
008 GTO 0   22 0      ... go back to label 0
009 RTN     43 21     Stop program - result displayed in x
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Example Program to calculate Factorial - damaltor - 01-31-2018 02:59 PM



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