News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Calculating Standard Deviation

Started by usafman2006, November 18, 2011, 01:51:07 PM

Previous topic - Next topic

usafman2006

I'm working on a program that will calculate the standard deviation of all or part of the fibonacci numbers.  I have created an array of the numbers, up to the 94th fibonacci number, but I'm not sure how to write the procedure to calculate the standard deviation.  Any helpful criticism would be appreciated, thanks!

dedndave

calculating the standard deviation is easier to understand if done in steps

1) calculate the mean (average) of all the values in the list
2) for each number in the list, calculate (Value-Mean)2
3) calculate the variance by taking the average of all those squared values
4) to obtain the standard deviation, take the squareroot of the variance

i would suggest using the FPU  :U
probably best to do it in 2 loops - the first pass to calculate the mean (step 1) - the second pass to do the rest (steps 2 and 3)
after the second loop, complete the calculation by taking the squareroot of the variance (step 4)
of course, when you are all done, you will need an additional step to convert the result to ASCII

Ray's FPU library may be of some help
his FPU tutorial is certainly going to be helpful
http://www.ray.masmcode.com/

usafman2006


usafman2006

I'm having an issue with my procedure to print the fibonacci array.  I'm having the user input a starting array index (0 to 93) and then prompting them to input the number of elements to display (1 to 94, obviously).  I thought it would be easiest to use a pointer to index 0 of the fibonacci array and then increment the pointer to the spot the user defined.  I'm not exactly sure how to do this as I've never had to really use pointers yet.  Any hints as to how I could achieve this? Or is there an easier way other than using pointers? 


DisplayFibArray PROC USES rax rcx rdx r8 r9 r10 r11 ;preserve volitile registers
sub rsp, 28h ;reserve stack space for local calls.
        xor rsi, rsi                ;clear rsi register
        xor rcx, rcx                ;clear rcx register
@@Strt1:lea rsi, Prompt1            ;Prompt user for starting index
        call PrintStr               ;print the string
        lea rsi, StartIndex ;point to start index
        call ReadStr ;read in the string
        cmp StartIndex,'0' ;compare storage value to zero
        jb @@Err1 ;  if below,jump to error
        lea rsi, StartIndex ;point to start index
        lea rdi, StrtIdx ;point to destination index
        call Ascii2Qword ;convert to number
@@Strt2:lea rsi, Prompt2            ;Prompt the user for # of elements to process
        call PrintStr               ;print the string
        lea rsi, NumElement         ;storage location for number of elements
        call ReadStr                ;read string of user input
        lea rsi, NumElement ;point to num element value
        lea rdi, NumElmt ;point to destination numelmt
        call Ascii2Qword ;convert to number
        mov rdx, StrtIdx ;copy strtidx into rdx
        mov rdx, OFFSET FibArray ;copy offset fibarray into rdx
        mov rsi, rdx ;copy rdx to rsi
        mov rcx, NumElmt ;copy numelmt into rcx
@@Start:lea rsi, [rdx] ;point to value stored in rdx
        lea rdi, Temp2 ;point to destination storage
        call Qword2Ascii ;convert to string
        lea rsi, Temp2 ;point to string
        call PrintStr ;  display the string
        loop @@Start ;  loop back to @@start
@@Err1: lea rsi, Error2 ;point to error2
        call PrintStr ;  display the string
        jmp @@Strt1 ;jump back to start1
@@Err2: lea rsi, Error3 ;point to error3
        call PrintStr ;  display the string
        jmp @@Strt2 ;jump back to start2
@@Done: add rsp, 28h ;restore stack space used for local calls             
ret ;return to caller
DisplayFibArray ENDP

mineiro

Hello Sr usafman2006;
Read the user input, transform it to internal computer number (are you using qword?). Lea your array in some register, multiply the transformed input number by 8(shl by 3), add to the register where array is pointed and read the contents of that position.

lea rax,fibo_array
mov rcx,transformed_input_number
shl rcx,3
add rax,rcx
mov rax,[rax]

Not the best example, but give you an idea.