%OUT-------------------------------------------------------------------------
%OUT- Computes LCM of two Integers
%OUT- input: the two numbers
%OUT- output: LCM of the entered numbers
%out – author: Ayon and Ariyam
%OUT-------------------------------------------------------------------------
if1
include macrolib.lby
endif
.model small
.stack
.data
in_msg1 db "Enter 1st no. ","$"
in_msg2 db " Enter 2nd no. ","$"
msg db "LCM of entered values: ","$"
.code
;---------------------------------------------------
; Computes the gcd of two numbers
; input: nos. are in BL & BH
; ouput: gcd will be in BL
; regs. affected: BX & AX
;---------------------------------------------------
gcd proc ;supply the two nos. in BL & BH
pushf
mov ax,0000h
cmp bl,bh
jb ok ;(BL)<(BH), no xchg needed
xchg bl,bh ;else exchange
ok: mov al,bh
lp: div bl
cmp ah,00h ;check if remainder zero
je done
;remainder not zero
mov al,bl
mov bl,ah ;final result will be in BL
mov ah,00h
jmp lp
done:
popf
ret
gcd endp
main proc
mov ax,@data
mov ds,ax
showmsg in_msg1
input
mov bl,al
push bx
space
showmsg in_msg2
input
pop bx
mov bh,al ;get the two nos. in bl & bh
push bx ;save the nos.
call gcd ;compute their gcd
pop cx ;get the nos. in CX
mov al,ch
mov ah,00h
mul cl
mov bh,00h
mov dx,0000h
div bx ;divide by gcd
push ax
mov bh,ah
space
showmsg msg
output
pop ax
mov bh,al
output
exit
main endp
end main
No comments:
Post a Comment
Do you think this information useful or was not up to the mark? Comment if you have any advices or suggestions about the post.