Forums before death by AOL, social media and spammers... "We can't have nice things"
|    comp.lang.asm.x86    |    Ahh, the lost art of x86 assembly    |    4,675 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 2,966 of 4,675    |
|    Rick C. Hodgin to Alex    |
|    Re: 64 bit stack alignment    |
|    29 Aug 17 09:07:45    |
      From: rick.c.hodgin@nospicedham.gmail.com              On Tuesday, August 29, 2017 at 11:14:38 AM UTC-4, Alex wrote:       > On 64 bit Windows, stack alignment on a 16 byte boundary is required       > before calling all except a leaf function. In the called function, the       > stack is 8 mod 16.       >       > Now, I'm struggling to come up with a way of doing it beyond this code       > (which I didn't invent, but I can't for the life of me remember where I       > found it.)       >       > push rsp       > push [rsp]       > and spl $F0       > call funkychicken       > pop rsp       >       > It seems to be the only way of doing this without branches, flags or       > other expensive nonsense. But, as ever, there may be a better way. Any       > suggestions?              I don't think the above solution will work. If I read it correctly       (as it appears to be mixing ISAs), you'll lose your relative stack       pointer position with the AND, and since it's an unknown (it will       either change the value of rsp or not), then it won't be reliable.              The only thing I can think of that doesn't involve branching is an       algorithm like this (completely untested, and I'm using r15 as an       arbitrarily chosen register, it can be changed to any other reg):               xor r15,r15        test rsp,0Fh ; See if we're already aligned        setnz r15b ; Set to 0 or 1 based on alignment        shl r15,3 ; Multiply by 8        sub rsp,r15 ; Adjust rsp by 0 or 8        call funkychicken ; Perform the normal call        add rsp,r15 ; Un-adjust rsp by 0 or 8              Note also that this has the effect of pushing your parameters up       on the stack an additional 8-bytes, so you may need to do this       first ... I don't know. I've always kept the stack 8-byte aligned       and everything worked, so I'm not really sure what you're doing       here.              Thank you,       Rick C. Hodgin              --- SoupGate-Win32 v1.05        * Origin: you cannot sedate... all the things you hate (1:229/2)    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca