SHOW:
|
|
- or go back to the newest paste.
1 | section .data | |
2 | ||
3 | section .bss | |
4 | ||
5 | section .text | |
6 | ||
7 | global test_distance ; makes function visible from extern | |
8 | ||
9 | x1 equ 4 ; pointer a float x1, needs 32 bit (4 bytes) | |
10 | x2 equ 8 ; puntatore a float x2, needs 32 bit (4 bytes) | |
11 | d equ 12 ; int 32 bit, dimension of vectors | |
12 | ||
13 | test_distance: | |
14 | - | mov ecx, [esp+x1] ; ESI = address of vector x1 |
14 | + | mov ecx, [esp+x1] ; ECX = address of vector x1 |
15 | - | mov edx, [esp+x2] ; EDI = address of vector x2 |
15 | + | mov edx, [esp+x2] ; EDX = address of vector x2 |
16 | - | mov eax, [esp+d] ; EBX = Number of elements in vectors |
16 | + | mov eax, [esp+d] ; EAX = Number of elements in vectors |
17 | ||
18 | ; Traverse vectors in reverse order | |
19 | fldz ; Load zero on top of stack (sum starts at zero) | |
20 | ||
21 | ; Sum the square of differences | |
22 | nextvec: | |
23 | ; Load the current vector elements | |
24 | fld dword [ecx+eax*4-4] | |
25 | fld dword [edx+eax*4-4] | |
26 | fsubp ; Find the difference | |
27 | fmul st0 ; Square the value | |
28 | faddp ; Add it to the current sum | |
29 | dec eax ; Go to previous element in the array | |
30 | jnz nextvec ; If EBX is zero we are finished | |
31 | ||
32 | fsqrt ; Distance = sqrt of sum of the square of the differences | |
33 | ; Distance is at the top of the stack in ST0 | |
34 | ; Functions returning a float place the result in ST0 | |
35 | ; to the caller | |
36 | ||
37 | ret |