===============================
Greatest Common Divisor Program (Version 1)
===============================
-IAN! Ian! D. Allen - idallen@ncf.ca
GCD Algorithm - http://www.idcc.net/canisius/cs110sp99/Class04/index.htm
Take two integers. If they are equal, you are done. Print out
one of them - this is the answer.
If they are not equal, decide which is larger and subtract the
smaller one from it. Keep the two smaller numbers and throw away
the bigger one.
If they are equal, stop; otherwise, repeat.
GCD Pseudocode
1 Input A and B
2 Repeat until A = B
3 If A < B Then
4 Set B to B - A
5 Else
6 Set A to A - B
7 Output A
8 Stop
;Label Mnem. Operand Comments.............
;----- ----- ------- ---------------------
IN ; (1) input two numbers
STO A
IN
STO B
TEST LDA A ; (2) WHILE A != B
SUB B
SKNZ
JMP ENDWH
LDA A ; (3) IF A < B ?
SUB B
SKN
JMP ELSE
LDA B ; (4) TRUE - subtract A from B
SUB A
STO B
JMP ENDIF ; (5)
ELSE LDA A ; (6) FALSE - subtract B from A
SUB B
STO A
ENDIF JMP TEST ; jump to TEST part of WHILE to repeat
ENDWH LDA A ; (7) output GCD
OUT
HLT ; (8) Stop!
A DAT ?
B DAT ?