Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. ; Program Description: Mean and Variance
  2. ; Author: Agis Diamantis
  3. ; Creation Date: 10/17/19
  4. ; Revisions: n/a
  5. ; Date: 10/17/19 Modified by:
  6.  
  7.  
  8. .386
  9. .model flat,stdcall
  10. .stack 4096
  11. ExitProcess proto,dwExitCode:dword
  12. INCLUDE Irvine32.inc
  13. .data
  14.  
  15. RAW WORD 10,12,8,17,9,22,18,11,23,7,30,22,19,6,7
  16. Diff WORD 15 DUP(?)
  17. Square WORD 15 DUP(?)
  18.  
  19. printMean BYTE "MEAN",0
  20. printVariance BYTE "VAR",0
  21.  
  22. .code
  23. main proc
  24. mov cl,(LENGTHOF RAW) ;loop counter
  25. mov esi,OFFSET RAW ;esi = 0 index value
  26. mov ebx, 0
  27.  
  28. findSum:
  29. movzx eax, byte ptr[esi] ;get the value from the array
  30. add ebx, eax ;add the values of the array
  31. mov eax,ebx
  32. add esi, 2 ;increment esi by 2 for WORD array
  33. loop findSum ;go to findSum repeat until cl=0
  34.  
  35. mov edx, OFFSET printMean ;print the mean string
  36. call WriteString
  37. mov ecx, (LENGTHOF RAW) ;get the length of the array
  38. cdq
  39. idiv ecx ;find Mean value mean = sum/length of the array
  40. call WriteDec ;print the mean value
  41. call Crlf
  42.  
  43. mov edx, eax
  44. mov cl(LENGTHOF RAW) ;loop counter
  45. mov esi,OFFSET RAW ;esi = 0 index value
  46. mov ebx,0
  47. ;loop for variance
  48. Variance:
  49. movzx eax, byte ptr[esi] ;get the value from the array
  50. sub eax,edx ;subtract mean value from eax value
  51. imul eax,eax ;find the square value
  52. mov eax,ebx
  53. add esi,2 ;increment esi by 2 for WORD array
  54. loop Variance ;repeat Variance until cl=0
  55.  
  56. mov edx, OFFSET printVariance ;print the variance string
  57. call WriteString
  58. mov ecx,(LENGTHOF RAW)
  59. cdq
  60. idiv ecx ;find the variance
  61. call WriteDec ;print the variance
  62. call Crlf
  63.  
  64.  
  65. invoke ExitProcess,0
  66. main endp
  67. end main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement