Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- section .data
- section .bss
- section .text
- global test_distance ; makes function visible from extern
- x1 equ 4 ; pointer a float x1, needs 32 bit (4 bytes)
- x2 equ 8 ; puntatore a float x2, needs 32 bit (4 bytes)
- d equ 12 ; int 32 bit, dimension of vectors
- test_distance:
- mov ecx, [esp+x1] ; ESI = address of vector x1
- mov edx, [esp+x2] ; EDI = address of vector x2
- mov eax, [esp+d] ; EBX = Number of elements in vectors
- ; Traverse vectors in reverse order
- fldz ; Load zero on top of stack (sum starts at zero)
- ; Sum the square of differences
- nextvec:
- ; Load the current vector elements
- fld dword [ecx+eax*4-4]
- fld dword [edx+eax*4-4]
- fsubp ; Find the difference
- fmul st0 ; Square the value
- faddp ; Add it to the current sum
- dec eax ; Go to previous element in the array
- jnz nextvec ; If EBX is zero we are finished
- fsqrt ; Distance = sqrt of sum of the square of the differences
- ; Distance is at the top of the stack in ST0
- ; Functions returning a float place the result in ST0
- ; to the caller
- ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement