GCD in 8085 Assembly
Published by Arun Isaac on
An 8085 microprocessor implementation of Euclid’s algorithm, an efficient method for computing the Greatest Common Divisor (GCD) of two integers.
This is an implementation of Euclid’s algorithm, an efficient method for computing the Greatest Common Divisor (GCD) of two integers.
main: MOV A, 0F ;load x
MVI C, 03h ;load y
loop: SUB C ;subtract lesser number from greater number
JNC loop
ADD C ;difference is negative, undo subtraction
JZ end ;if difference is zero, end
swap: MOV B, A ;else, swap
MOV A, C
MOV C, B
JMP loop ;continue subtraction
end: MOV A, C ;store result
STA 4300h
HLT