Wednesday, 8 April 2009

Square Root

;8086 program that computes the square root of a perfect square number

data segment
msg1 db "Enter the number:$"
msg2 db 0ah,0dh, "The entered number is not a perfect square$"
msg3 db 0ah,0dh, "Square root is:$"
data ends

print macro msg
lea dx,msg
mov ah,09h
int 21h
endm

read macro
mov ah,01h
int 21h
sub al,30h
mov bh,0ah
mul bh
mov bl,al
mov ah,01h
int 21h
sub al,30h
add bl,al
endm

disp macro reg
mov dl,reg
mov ah,09
int 21h
endm

code segment
start:
mov ax,data
mov ds,ax

print msg1
read

mov cl,00h
mov ch,01h
l3:
sub bl,ch
jc l2
jz l1
;aas
inc cl
inc ch
inc ch
jmp l3
l1:
inc cl
print msg3
add cl,30h
mov dl,cl
mov ah,02h
int 21h
jmp k
l2:
print msg2
k:
mov ah,4ch
int 21h
code ends
end start

;Program Ends Here

querrymail@gmail.com

0 comments: