Euclid (a Greek mathematicians and philosopher of about 300 BC) describes this algorithm in Propositions 1 and 2 of Book 7 of The Elements, although it was probably known to the Babylonian and Egyptian mathematicians of 3000-4000 BC also.
If we try it with an two numbers, the final non-zero remainder is the greatest number that is an exact divisor of both our original numbers (the greatest common divisor)
Here is the program
mov ax,4000h
mov ds,ax
mov si,0000h
mov al,num1 ;num1 is first no.
mov cl,num2 ;num2 is second no.
mov ah,00h
cmp al,cl
ja next
xchg al,cl
next: mov bl,cl
div cl
cmp ah,00h
je down
mov al,cl
mov cl,ah
mov ah,00h
jmp next
down mov result,bl ;result is the mem.loc.
;where gcd is to be stored
hlt
You might be also interested in:
:: options available for int 21h instruction
:: Answers of Microprocessor(8085) & Electronics FAQ
:: The 8085 Microprocessor Architecture Microprocessors & Interfacing
No comments:
Post a Comment