The Museum of HP Calculators


Modulo, GCD, and LCM for the HP 20s, 21S

This program is by Dave Britten and is used here by permission.

This program is supplied without representation or warranty of any kind. Dave Britten 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.

Overview

LBL A: GCD
LBL B: LCM
LBL F: Modulo
Usage:
x, INPUT, y, XEQ A/B/F

Unneeded programs can be skipped, however LBL A depends on LBL F, and LBL B depends on LBL A and LBL F. The checksum assumes all programs are entered as supplied.

The modulo routine uses no storage registers, and makes liberal (mis)use of INPUT, SWAP, and LAST to accomplish this. GCD uses storage registers 1 and 2, and LCM uses register 3 in addition to 1 and 2.

Checksum: 843A

Listing

01-	LBL A
02-	STO 2
03-	SWAP
04-	STO 1
05-	SWAP
06-	LBL 1
07-	x=0?
08-	GTO 2
09-	XEQ F
10-	SWAP
11-	RCL 2
12-	STO 1
13-	SWAP
14-	STO 2
15-	GTO 1
16-	LBL 2
17-	SWAP
18-	RTN
19-	LBL B
20-	STO 2
21-	SWAP
22-	STO 1
23-	*
24-	RCL 2
25-	=
26-	STO 3
27-	RCL 1
28-	SWAP
29-	XEQ A
30-	/
31-	RCL 3
32-	SWAP
33-	=
34-	RTN
35-	LBL F
36-	=
37-	(
38-	SWAP
39-	INPUT
40-	=
41-	/
42-	LAST
43-	)
44-	IP
45-	*
46-	LAST
47-	=
48-	(
49-	SWAP
50-	-
51-	LAST
52-	=
53-	RTN

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