UP | HOME

HP Voyager Programs
ForHP-16C

Author: Mitch Richling
Updated: 2024-02-27
Generated: 2024-02-27

Copyright © 2024 Mitch Richling. All rights reserved.

Table of Contents

1. Introduction

Dedicated "computer scientist" calculators have never been popular with only a few models ever offered on the market. The HP-16C remains, more than 40 years after its introduction, the most powerful "computer scientist" calculator ever produced. Unlike my programs for the HP-15C, the code here is all about adding new functionality to the calculator.

I have one "big" program on my HP-16C & DM-16L calculators with 7 entry points:

LBL Function Description
A SLn Shift Y left by X bits
B SRn Shift Y right by X bits
C ctz Count Trailing Zeros
E iLog Integer logarithm: floor(log2(x))
F WSIZE Recall the WSIZE value
2 2^x Compute 2x
1 LSSB Clear all but least significant set bit

1.1. Stack Diagrams

SLn – Shift y left by x bits

  Before After
T: t ?
Z: z ?
Y: y ?
X: n SLn(y, n)

SRn – Shift y right by x bits

  Before After
T: t ?
Z: z ?
Y: y ?
X: n SRn(y, n)

ctz – Count Trailing Zeros

  Before After
T: t ?
Z: z ?
Y: y ?
X: x CTZ(x)

iLog – Integer logarithm: floor(log2(x))

  Before After
T: t ?
Z: z ?
Y: y ?
X: x iLog(x)

WSIZE – Recall the WSIZE value

  Before After
T: t y
Z: z y
Y: y x
X: x WSIZE

2^x – Compute 2x

  Before After
T: t z
Z: z z
Y: y y
X: x 2x

LSSB – Clear all but least significant set bit

  Before After
T: t y
Z: z y
Y: y y
X: x LSSB(x)

1.2. Program Listing

Keystrokes     Key Codes     Stack Contents     Comments
g LBL A 43,22, A n y z t   A SLn – Shift Left n bits
GSB 2 21 2 2^x y z ?    
× 20 SLn(x) z ? ?   Ret
g RTN 43 21      
g LBL B 43,22, b n y z t   B SRn – Shift Right n bits
GSB 2 21 2 2^x y z ?    
÷ 10 SRn(x) z ? ?   Ret
g RTN 43 21      
g LBL C 43,22, C x y z t   C CTZ – Count Trailing Zeros
g x=0 43 40 x y z t    
÷ 10 0 y z t   Ret when x=0
GSB 1 21 1 LSSB y ? ?    
GSB E 21 E CTZ(x) y ? ?   Ret when x≠0
g RTN 43 21      
g LBL E 43,22, E x y z t   E iLog – Integer logarithm: floor(log2(x))
g x=0 43 49 x y z t    
÷ 10 0 y z t   Ret when x=0
g LJ 43 A c ljx y z    
x≷y 34 ljx c y z    
R↓ 33 c y z ljx    
GSB F 21 F wsize c y ?    
1 1 1 wsize c y    
- 30 wsize-1 c y y    
x≷y 34 c wsize-1 y y    
- 30 iLog(x) y y y   Ret when x≠0
g RTN 43 21      
g LBL F 43,22, F x y z t   F WSIZE – Recall the WSIZE value
1 1 1 x y z    
g LJ 43 A ws-1 1s x y    
x≷y 34 1s ws-1 x y    
R↓ 33 ws-1 x y 1s    
1 1 1 ws-1 x y    
+ 40 wsize x y y   Ret
g RTN 43 21      
g LBL 2 43,22, 2 x y z t   2 2^x – Compute 2x
1 1 1 x y z    
x≷y 34 x 1 y z    
f RLn 42 e 2^X y z z   Ret
g RTN 43 21      
g LBL 1 43,22, 1 x y z t   1 LSSB – Clear all but least significant set bit
g x=0 43 40 x y z t    
g RTN 43 21 0 y z t   Ret when x=0
ENTER 36 x x y z    
ENTER 36 x x x y    
1 1 1 x x y    
- 30 x-1 x y    
f NOT 42 30 NOT(x-1) x y y    
f AND 42 20 LSSB(x) y y y   Ret when x≠0
g RTN 43 21      

2. Meta Data

The primary URL for this page: https://richmit.github.io/voyager/hp16.html

The org mode file for this page: https://github.com/richmit/voyager/blob/main/docs/hp16.org

The HTML file for this page: https://github.com/richmit/voyager/blob/main/docs/hp16.html

The github repository housing this content: https://github.com/richmit/voyager/