06-Write 8087 ALP to obtain MEAN ,VARIANCE & STANDARD DEVIATION for given set of data elements defined in data segment.

Write 8087 ALP to obtain:
          1)MEAN
          2)VARIANCE
          3)STANDARD DEVIATION
        for given set of data elements defined in data segment. Also display result.

.model small

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



.data

num1 dd 3.0
num2 dd 4.0
num3 dd 5.0
three dw 0003
answer dt ?
temp dd 10000.0
result db 00h
cnt db 0Ah

msg1 db 10,13,"The MEAN of the THREE Numbers is: $"
msg2 db 10,13,"The VARIANCE of the THREE Numbers is: $"
msg3 db 10,13,"The STANDARD DEVIATION of the THREE Numbers is: $"


.code

main:
mov ax,@data
mov ds,ax

;MEAN
finit ;initialisation              
fld num1 ;load 1st no.
fld num2
fld num3
fadd st(0),st(1)
fadd st(0),st(2)
fmul temp
fidiv three
fbstp answer
disp msg1
call ans


;VARIANCE
finit
fbld answer
fdiv temp
fld num1
fsub st(0),st(1)
fmul st(0),st(0)
fbld answer
fdiv temp
      fld num2
      fsub st(0),st(1)
      fmul st(0),st(0)
      fbld answer
      fdiv temp
      fld num3
      fsub st(0),st(1)
      fmul st(0),st(0)
      fadd st(0),st(2)
      fadd st(0),st(4)
      fmul temp
      fidiv three
      fbstp answer
      disp msg2
      call ans


;STANDARD DEVIATION
finit
      fbld answer
      fdiv temp
      fsqrt
      fmul temp
      fbstp answer
      disp msg3
      call ans


mov ah,4ch
int 21h


ans proc near

mov cnt,0Ah
lea SI,answer
add SI,09

up1:
mov bl,[SI]
mov result,bl
call print
dec SI
dec cnt
cmp cnt,02h
jne up1

mov dl,'.'
mov ah,02h
int 21h

up2:
mov bl,[SI]
mov result,bl
call print
dec SI
dec cnt
cmp cnt,00h
jne up2

ret
ans endp


print proc near
mov bl,result
          mov bh,00h
          shr bl,04h
          cmp bl,09h
          jle down1
          add bl,07h
         
down1:
            add bl,30h
            mov dl,bl
            mov ah,02h
            int 21h

          mov bl,result
          mov bh,00h
          and bl,0Fh
          cmp bl,09h
          jle down2
          add bl,07h
       
down2:
            add bl,30h
            mov dl,bl
mov ah,02h
int 21h

ret
print endp
   
   end main
end




-------------------------------------------------OUTPUT------------------------------------------------

D:\tasm\BIN>edit mean.asm

D:\tasm\BIN>tasm mean.asm
Turbo Assembler  Version 4.1  Copyright (c) 1988, 1996 Borland International

Assembling file:   mean.asm
Error messages:    None
Warning messages:  None
Passes:            1
Remaining memory:  449k


D:\tasm\BIN>tlink mean.obj
Turbo Link  Version 7.1.30.1. Copyright (c) 1987, 1996 Borland International
Warning: No stack

D:\tasm\BIN>mean

The MEAN of the THREE Numbers is: 0000000000000004.0000
The VARIANCE of the THREE Numbers is: 0000000000000000.6667
The STANDARD DEVIATION of the THREE Numbers is: 0000000000000000.8165
D:\tasm\BIN>

Previous
Next Post »

Disqus Shortname

Comments system