Assembly returns a pointer using malloc
I am just training assembly with a coprocessor. The thing is, I don't know how to return a pointer to my value.
Code in C:
double * distance(float x, float y, float z);
And my assembly code:
.code
_distance PROC
push ebp
mov ebp, esp
mov eax, 0
finit ; some aritmetic
fldz
fld dword PTR [ebp + 8]
fsubp st(1), st(0)
fmul st(0), st(0) ; 0 - x
fldz
fld dword PTR [ebp + 12]
fsubp st(1), st(0)
fmul st(0), st(0)
fldz
fld dword PTR [ebp + 16]
fsubp st(1), st(0)
fmul st(0), st(0)
faddp st(1), st(0)
faddp st(1), st(0)
fsqrt
push 10 ; first i push 10 bytes for malloc
call _malloc
add esp, 4
fstp [eax], st(0) ; and then i want to point to the specific value
pop ebp
ret
_distance ENDP
As far as I know, malloc allocates memory and returns the address in eax. So the only thing I want to know is how to point to the co-op register value and return it.
+3
source to share
No one has answered this question yet
Check out similar questions:
eleven