-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMEAN_VARIANCE_STANDARDDEV.asm
154 lines (128 loc) · 1.71 KB
/
MEAN_VARIANCE_STANDARDDEV.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
%macro println 2
mov rax,01h
mov rdi,01h
mov rsi,%1
mov rdx,%2
syscall
%endmacro
segment .data
array dd 115.1,112.2,418.3,410.4,125.5
mdivfact dw 5
precFact dw 10000
msg1 db 10,'Mean Value is :'
len1 equ $-msg1
msg2 db 10,'Variance is :'
len2 equ $-msg2
msg3 db 10,'Standard Deviation is :'
len3 equ $-msg3
dot db '.'
section .bss
meanP resb 10
mean resb 4
variP resb 10
vari resb 4
stdDev resb 10
display resb 2
section .text
global _start
_start:
finit
mov rsi,array
mov cl,05h
fldz ;floadzero
addNext:
fadd dword[rsi]
add rsi,04h
dec cl
jnz addNext
fild word [mdivfact]
fdiv
fst dword [mean]
fild word [precFact]
fmul
fbstp [meanP]
println msg1,len1
mov rsi,meanP+9
call dispBcd
mov cl,05h
mov rsi,array
fldz
again1:
fld dword [rsi]
fld dword [mean]
fsub
fmul st0,st0
fadd
add rsi,04h
dec cl
jnz again1
fild word [mdivfact]
fdiv
fst dword [vari]
fild word [precFact]
fmul
fbstp [variP]
println msg2,len2
mov rsi,variP+9
call dispBcd
fld dword [vari]
fsqrt
fild word [precFact]
fmul
fbstp [stdDev]
println msg3,len3
mov rsi,stdDev+9
call dispBcd
mov rax,60
syscall
dispBcd:
mov cl,10
mov ch,00h
;Flag for checking . printed or not
dispNext:
cmp cl,02h
jne goAhead
push rcx
push rsi
println dot,1
pop rsi
pop rcx
mov ch,01h
goAhead:
mov bl,[rsi]
cmp ch,01h
je goDisp
cmp bl,00h
je skip
goDisp:
push rcx
push rsi
call displayNo
pop rsi
pop rcx
skip:
dec rsi
dec cl
jnz dispNext
ret
displayNo:
mov al,bl
and al,0f0h
mov cl,04h
shr al,cl
add al,30h
cmp al,39h
jle dontAdd
add al,07h
dontAdd:
mov [display],al
mov al,bl
and al,0fh
add al,30h
cmp al,39h
jle dontAddd
add al,07h
dontAddd:
mov [display+1],al
println display,2
ret