; PROGRAM: SQUARE ROOT
read macro num
mov ah, 01h
int 21h
mov bh, al
int 21h
mov bl, al
sub bh, 30h
mov al, 0ah
mul bh
sub bl, 30h
add al, bl
mov num, al
endm
print macro s
mov ah, 09h
mov dx, offset s
int 21h
endm
data segment
msg db 'Enter Number: $'
rootis db 'Square root is: $'
nl db 0dh,0ah,'$'
num db 00h
sroot db 00h
proot db 11 dup('$')
data ends
code segment
assume cs:code, ds:data
start:
mov ax, data
mov ds, ax
print msg
read num
mov al, num
mov cl, 00h
mov bl, 01h
REPSUB:
cmp al, 00h
je STOP_E
jl STOP_LT
sub al, bl
inc cl
add bl, 02h
jmp REPSUB
STOP_LT:
dec cl
STOP_E:
mov al, cl
mov ah, 00h
mov si, offset proot
call hex2ascii ;converts hex in ax
print nl ;to ascii into si loc
print rootis
print proot
mov ah, 4ch
int 21h
hex2ascii proc near
mov cx, 0000h
REPDIV:
mov dx, 0000h
mov bx, 000ah
div bx
add dl, 30h
push dx
inc cx
cmp ax, 000ah
JGE REPDIV
add al, 30h
mov [si], al
inc si
SAVEASCI:
pop dx
mov [si], dl
inc si
loop SAVEASCI
STOP1:
mov [si], '$'
ret
hex2ascii endp
code ends
end start
**************************
OUTPUT
Z:\S5IT\masm>SQ_ROOT
Enter Number: 25
Square root is: 05
Z:\S5IT\masm>SQ_ROOT
Enter Number: 37
Square root is: 06
Z:\S5IT\masm>SQ_ROOT
Enter Number: 49
Square root is: 07
**************************
0 comments:
Post a Comment