3

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.

Dave
  • 8,163
  • 11
  • 67
  • 103
SteepZero
  • 334
  • 2
  • 8

1 Answers1

4

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
rcgldr
  • 27,407
  • 3
  • 36
  • 61
  • This is semi-useful advice; if you're executing an `fsave (%esp)` _after the above_, you will overwrite existing stack. While you need to align the stackpointer, don't forget you _also must allocate_ stack here ... – FrankH. Feb 17 '14 at 16:25
  • 1
    updated the code example. my old documentation notes that fsave can save up to 108 bytes, it might be bigger now. – rcgldr Feb 17 '14 at 19:52