The Museum of HP Calculators

Blackjack for the HP-32s

This program is released to the public domain by Joseph R Power and is used here by permission.

This program is supplied without representation or warranty of any kind. Joe Power and The Museum of HP Calculators therefore assume no responsibility and shall have no liability, consequential or otherwise, of any kind arising from the use of this program material or any part thereof.


This is a revision of a Blackjack program I originally wrote for the HP25. It treats aces as 1s or 11s, draws on 16, stands on 17.

(The original HP25 version, which I'm still looking for, used every programming step, every memory register and all 4 levels of the stack.)

D dealer's total
E # of aces in dealer's total counted as 11
P player's total
Q # of aces in player's total counted as 11
W # of dealer and player wins
X total passed to card generation routine
Y # of aces counted as 11 passed to card generation routine

To Play:
press GTO A
program will show dealer's first card (as negative)
program will then show player's first card and then player's total
to hit, player presses R/S
to stand, player presses CHS R/S
if player busts, show dealer's & player's win totals
program will show dealer's total (as negative)
dealer must hit on 16 or less and stand on 17 or more
if dealer busts, show dealer's & players win totals
compare dealer's total to player's total (dealer wins ties)
show dealer's & players win totals

Possible Improvements:
* Allow bets.
* Keep player wins as integers and use logarithms to convert totals decimals with no leading zeros.


A01 LBL A		Blackjack
A02 0			clear player's & dealer's win totals

B01 LBL B		next round init routine
B02 ALL			set display mode
B03 0
B04 STO D		clear dealer's total
B05 STO E		clear # of dealer's aces
B06 STO P		clear player's total
B07 STO Q		clear # of player's aces
B08 XEQ I		draw dealer's first card
B09 +/-			show total as negative
B11 XEQ U		draw player's first card
B12 PSE			show total and fall thru

G01 LBL G		Player's hit/stand loop
G02 XEQ U		draw player's next card
G03 PSE			show total
G04 21			has player exceeded 21?
G05 X<Y?
G06 GTO W		if so, go to dealer wins
G07 Rv			show total again
G08 STOP		wait for hit/stand choice
G09 X>0?		(press CHS to stand)
G10 GTO G		not pressing CHS means hit	

H01 LBL H		Dealer's hit/stand loop
H02 XEQ I		draw dealer's next card
H03 +/-			show total as negative
H05 +/-
H06 21			has dealer exceeded 21?
H07 X<Y?
H08 GTO L		if so, go to dealer loses
H09 Rv			get total into X again
H10 17			dealer must stand on 17+
H11 X>Y?
H12 GTO H		otherwise, he must hit
H13 Rv			get total into X again
H14 RCL P 		compare with player's total
H15 X>Y?			
H16 GTO L		if smaller, dealer loses
H17 GTO W		otherwise, dealer wins

I01 LBL I		Draw dealer's next card routine
I02 RCL D		pass dealer's total and # of aces
I03 STO X		to draw card routine
I06 XEQ C		draw a card
I07 RCL Y		record new total and # of aces
I08 STO E		from draw card routine

U01 LBL U		Draw player's next card routine
U02 RCL P		pass player's total and # of aces
U03 STO X		to draw card routine
U06 XEQ C		draw a card
U07 RCL Y		record new total and # of aces
U08 STO Q		from draw card routine

C01 LBL C		Draw card routine
C02 RANDOM		generate a random integer
C03 13			from 0 to 12
C04 *
C05 IP
C06 9			handle face cards (9 to 12)
C07 X<Y?
C08 GTO D		(all face cards set to 9)
C09 Rv			handle non-aces
C10 X != 0	
C12 1			handle aces
C13 STO + Y		increment # of aces variable
C14 10			fall thru to D with ace's value in x

D01 LBL D		
D02 1			normalize card value to 2 to 11
D03 +
D04 STO + X		add to total
D05 RCL X		if total hasn't exceeded 21
D06 22
D07 X>Y?
D08 RTN			then return total and # of aces
D09 RCL Y		otherwise, see if any aces counting as 11s
D10 X=0?		in total
D11 RTN			if not, return total and # of aces
D12 10			otherwise, change an ace in total from 11 to 1
D13 STO - X
D14 1			and decrement # of unchanged aces
D15 STO - Y
D16 RTN			then return total and # of aces

L01 LBL L		Dealer loses 
L02 3			add .001 to # of player's wins
L03 10^X	
L04 1/X
L05 STO + W
L06 GTO K		display dealer vs player wins

W01 LBL W		Dealer wins
W02 1			add 1 to # of dealer's wins
W03 STO + W		(fall thru)

K01 LBL K		Display dealer vs player wins
K02 FIX 3		set display mode
K03 RCL W		dealer's wins . player's wins
K03 STOP		display win totals
K04 GTO B		play again

Go back to the software library
Go back to the main exhibit hall