Search code examples
assemblystackmemory-addressmemory-alignmentfpu

How to get 16 byte aligned address in assembly


I have to save floating-point registers into the stack.
I tried to use fsave instruction.
I do the following:

fsave (%esp)

But as an argument fsave uses 16 byte aligned address.

I don't have an idea how to make address in %esp be 16 byte aligned.


Solution

  • Using intel style syntax:

        push    ebp             ;save ebp
        mov     ebp,esp         ;save esp in ebp
        and     esp,0fffffff0h  ;round esp down to 16 byte boundary
        sub     esp,128         ;allocate multiple of 16 bytes