I have an array of real numbers in 32-bit architecture
it holds he higher and lower order values in ecx, edx
i'm able to enter them in into the array and output them as well
but i'm having difficulty adding all them up
here is code so far(gives a segfault)
any input is helpfull
addarray:
push ebx
push ebp
push edi
push ecx
push esi
mov edi, 0 ;initialize counter to 0
mov esi, 0 ;initialize accum to 0
mov ecx, 0 ;zero out ecx and edx
mov edx, 0
mov ebx, [ebp] ;moves starting location of array1 into ebx
mov edi, [ebp+12] ;moves array size
add_loop:
mov ecx, [ebx] ;mov higher order
mov edx, [ebx+4] ;mov lower order
push ecx
push edx
fld qword [ebx] ;The second input is now in a floating point register, specifically st0.
pop dword ebp
pop dword ebp ;The first input is now on top of the system stack (the stack addressed by bytes)
fadd qword [ebx] ;The first input is added to the second input and the sum
;replaces the second input in st0
add ebx,8
inc edi
cmp esi, edi
jz add_done
jmp add_loop
add_done:
mov eax, summessage ;Setup to display a message
call print_string ;Dr. Carter's library
push dword 0 ;Make space on sytem stack for the sum value
push dword 0 ;Ditto
fst qword [ebx] ;Copy contents of st0 to space currently on top of the system stack
pop ecx ;Copy 4 MSBs to ecx
pop edx ;Copy 4 LSBs to ecx
call writedouble ;Show the 8-byte value
call print_nl ;Newline
pop esi
pop ecx
pop edi
pop ebp
pop ebx
ret