=============================== Greatest Common Divisor Program (Version 2) =============================== -IAN! Ian! D. Allen - idallen@ncf.ca Take two integers. Put one into "large" and one into "small". Repeat until "small" equals "large": If "small" is bigger than "large", swap the numbers. Subtract "small" from "large" and put result in "large". Output "small". GCD Pseudocode 1 input S and L 2 while S != L 3 If S > L Then 4 Set tmp to S 5 Set S to L 6 Set L to tmp 7 Set L to be L - S 8 Output A 9 Stop ;Label Mnem. Operand Comments............. ;----- ----- ------- --------------------- IN ; (1) input two numbers STO S IN STO L TEST LDA S ; (2) WHILE S != L SUB L SKNZ JMP ENDWH LDA L ; (3) IF S > L ? SUB S SKN JMP ENDIF LDA S ; (4) TRUE - swap numbers STO TMP LDA L ; (5) STO S LDA TMP ; (6) STO L ENDIF LDA L ; (7) subtract small from large SUB S STO L JMP TEST ; jump to TEST part of WHILE to repeat ENDWH LDA S ; (7) output GCD OUT HLT ; (8) Stop! L DAT ? S DAT ? TMP DAT ?