Using pointers to return results in x86 Assembly

Viewed 89

We've been given the following function to try and implement in C as part of a CS course. We are programming on x86 Linux.

function(float x, float y, float *z);

For a function such as example(int x, int y) I understand that the x value resides at [ebp+8] and y at [ebp+12] on the stack, is the same convention used when pushing floats?

We also have to perform some masking and calculations on the float numbers. Do these float numbers behave the same as 32-bit integers just in IEEE-754 format?

1 Answers

here is a simple function and it's asm code :

function(float x, float y, float *z){

    float sum = x + y;
    float neg = sum - *z;

}

the asm of the above function will be like this:

function:
        pushl %ebp
        movl %esp,%ebp
        subl $8,%esp
        pushl %ebx
        flds 8(%ebp)
        fadds 12(%ebp)
        fstps -4(%ebp)
        movl 16(%ebp),%ebx
        flds -4(%ebp)
        fsubs (%ebx)
        fstps -8(%ebp)
        leal -12(%ebp),%esp
        popl %ebx
        leave
        ret

as you can see from asm above the reference to ebp+x in this case x will be 8/12/16 to get the parameter from the stack, so as fuz point out it in the comments it is indeed stored on the stack

Related