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
c assembly pointers


source to share


No one has answered this question yet

Check out similar questions:

3076
What are the differences between a pointer variable and a reference variable in C ++?
2296
Output malloc result?
1699
What is a smart pointer and when should I use it?
1483
Why should I use a pointer and not the object itself?
206
What is a base pointer and a stack pointer? What do they point to?
26
Base pointer and stack pointer
eleven
What is% gs in Assembly
2
Add constant value to register xmm in x86
2
(VC ++) Execution check for uninitialized variables: how is testing done?
0
Need help clarifying simple assembly code and feedback on my analysis



All Articles
Loading...
X
Show
Funny
Dev
Pics