Skip to content

Instantly share code, notes, and snippets.

@0xD9D0
Created May 4, 2018 09:55
Show Gist options
  • Save 0xD9D0/579e55114ebc0173759d4f15d1519218 to your computer and use it in GitHub Desktop.
Save 0xD9D0/579e55114ebc0173759d4f15d1519218 to your computer and use it in GitHub Desktop.

A hundred element, word-sized signed array has been stored in the data segment with starting at label IN_Data. Write a program to calculate the Variance of this array data as given in the equation. The results should be stored as Hexadecimal value in the data segment with label OUT_Data. To calculate the variance the mean should be calculated first as shown in the equation.
Equation

STSEG SEGMENT STACK
DB 32 DUP(?)
STSEG ENDS
;............................
DTSEG SEGMENT
ORG 10h
Data_IN DW 12,928,34,859,92,40,14,82,50,20
COUNT DW 10
AVRG DW (?)
STNDV DD 00CDH
ORG 30h
X_AVG DW 10 DUP(?)
;..........................
CDSEG SEGMENT
START:
ASSUME CS:CDSEG,DS:DTSEG,SS:STSEG
MOV AX,DTSEG
MOV DS,AX
MOV AX,0000H
MOV DI,0000H
MOV DX,0000H
MOV BX,0000H
MOV SI,0000H
MOV CX,[COUNT]
CLC_AVG: ADD AX, word ptr [Data_IN+SI]
ADC DX, 0000H
ADD SI,2
LOOP CLC_AVG
MOV CX, [COUNT]
IDIV CX
MOV word ptr [AVRG], AX
MOV SI,0
CLC_X: MOV BX,[Data_IN+SI]
SUB BX,AX
MOV [X_AVG+SI],BX
ADD SI,2
LOOP CLC_X
MOV SI,0
MOV BX,0000H
MOV CX,[COUNT]
CLC_STD: MOV AX,[X_AVG+SI]
IMUL AX
ADD BX,AX
ADC DI,DX
ADD SI,2
LOOP CLC_STD
MOV AX,BX
MOV DX,DI
MOV CX,[COUNT]
IDIV CX
MOV WORD PTR[STNDV],AX
MOV WORD PTR[STNDV+2],DX
INT 3H
ENDS
END START
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment