HP-16C programs

press g P/R to toggle programming mode, GTO . <nnn> to jump to a line, BSP to delete a line, and g RTN to end a program.

table of contents

exponent function

(for positive integers only. uses 2 stack and registers I, 0)

borrowed from this blog and modified avoid messing up stack

numkeysdisplaydescription
001LBL E43,22, Econvenient entry point
002STO I44 Istore in I
003R↓33pop old I value
004STO 044 0store in 0
005DSZ43 23decrement I and nop branch
006LBL 043,22, 0label for loop target
007RCL 045 0push 0 to stack
008*20multiply it
009DSZ43 23decrement and branch unless 0
010GTO 022 0I is not 0, loop again
011RTN43 21return

natural log

(uses 3 stack, flag 0, and registers I, 0)

based on part of an algorithm from Valentín Albillo's Boldly Going article but reworked to not mess up the stack

numkeysdisplaydescription
012LBL 743,22, 7entry point
013ENTER36dup
0141/x43 26inverse
015CF 043, 5, 0default flag
016x>y43 3input<1?
017SF 043, 4, 0save for later
018+40add inverse
01922float mode:
020/10no shifts ;_;
02111put 1
022STO I44 32into I
02311
02455
025EEX42 49
026CHS49
02766make big const
028+401+ from before
029x<->y34swap for inp n
030LBL 943,22, 9loop target
031STO 044 0store old val
03211
033+40increment
03422
035/10halve
036sqrt43 25
037ISZ43 24increment I
038x>y43 3x>y?
039GTO 922 9yes, loop
040R↓33
041R↓33pop unneeded
042RCL 045 0restore old
04311
044-30decrement
045ENTER36
046+40double
047sqrt43 25
048DSZ43 23put I back
049DSZ43 23decrement I
050LBL 843,22, 8loop target
051ENTER36
052+40double
053DSZ43 23decrement I
054GTO 822 8I not 0, loop
055F? 043, 6, 0recall input<1
056CHS49yes, negate
057RTN43 21return

factorial

(for integers > 1 only. uses 2 stack and register I)

numkeysdisplaydescription
058LBL F43,22, Fentry point
059STO I43 32store in I
060DSZ43 23skip first
061LBL 443,22, 4loop target
062RCL I45 32push I
063*20multiply I
064DSZ43 23decrement I
065GTO 422 4not 0? loop
066RTN43 21return