flat assembler
Message board for the users of flat assembler.
![]() Goto page Previous 1, 2, 3, 4, 5, 6 Next |
Author |
|
Ali.Z
i think some members here answered this multiple times, please refer to the 64-bit calling conventions. (msdn and wikipedia)
additionally a 32 bytes of shadow space may be required, besides that and since during the load time of your application the stack may not be aligned depending on Windows version; thus you cant always subtract 8 from RSP. instead subtract some 16 bytes value from RSP then bitwise AND SPL with F0h. Code: sub RSP,100h ; just for the sake of example and SPL,0F0h ; to ensure the alignment _________________ Asm For Wise Humans |
|||
![]() |
|
Roman
Ali.Z
Quote: thus you cant always subtract 8 from RSP. And how do pushs ? |
|||
![]() |
|
revolution
Okay.
So here is the situation. Start is unaligned, because you use the entry directive directly. After sub and then push the stack is unaligned. After the call the stack is aligned. This is a violation of the call standard. All procedure entries must be unaligned entry after the call, and the code must then align, usually with push rbp. Because you use proc this is done for you by the macro. Therefore the stack is not in the correct state. And KABOOM! To fix this, do not push a single value to the stack. Always push in pairs, or better yet, don't ever push, just use local variables. Last edited by revolution on 22 Dec 2020, 08:40; edited 1 time in total |
|||
![]() |
|
Roman
Quote:
I understood this many pages ago ![]() And try say this problem. In 32 bit program no this problem ! When i do push double(dq value) i not get crash ! Last edited by Roman on 22 Dec 2020, 08:44; edited 1 time in total |
|||
![]() |
|
revolution
So why are you asking the question if you already knew?
|
|||
![]() |
|
Roman
I wanted to confirm my guess. Test program on others CPUs.
And know this is not my wrong code. And remember this again, after couple years. Last edited by Roman on 22 Dec 2020, 08:49; edited 1 time in total |
|||
![]() |
|
revolution
The 32-bit call standard is completely different. You can't compare them.
|
|||
![]() |
|
Roman
Quote: The 32-bit call standard is completely different. That is why i very surprised when my program 64 bit crash. I thinked the same must work in 64 bits. |
|||
![]() |
|
Roman
But if fasmw have some function to get know align rsp or not.
And not do always in invoke sub rsp,20h and add rsp,20h Do smart sub rsp and add rsp. Its solve problem. My example work if write in proc vv: Code: proc vv sub rsp,20h-8 xor rcx,rcx mov rdx,text xor r8,r8 xor r9,r9 Call [MessageBox] add rsp,20h-8 ret text db 'some text',0 endp in code: push rax call vv pop rax |
|||
![]() |
|
revolution
Just follow the rules and then you will have no problem.
Always have your stack aligned before doing call, then it always works, always. If you have random "fixed" entries then you get trouble. Code: ; rsp is aligned push rax ;unaligned call vv ; okay, because vv has a fixup in there pop rax ; aligned call vv ; KABOOM! |
|||
![]() |
|
Roman
Quote:
I agree and that's why I started talking about a smart mechanism in fasmw 64 bits. Fasmw must follow rsp and know rsp aligned or not. And put right x value in sub rsp,x |
|||
![]() |
|
revolution
No.
fasm does what you tell it to do. Just follow the rules. If you have all those random stack adjustments with push then you get problems. Don't do it. Stop doing it. Never do it. Then all will work fine, no need for any special unruly code to "fix" the problems you created. |
|||
![]() |
|
Roman
Quote:
Do it but remember this ![]() And how i sayed best solution not do push rax and pop rax. Do mov [tmpRegs],rax Or macro NewPush reg { mov [tmpReg#reg],reg } Last edited by Roman on 22 Dec 2020, 09:45; edited 3 times in total |
|||
![]() |
|
revolution
Yes. Use local variables. Then you get a nice name attached, and no more problems.
|
|||
![]() |
|
Roman
Now you see too.
push and pop in 64 bits get problems. |
|||
![]() |
|
revolution
You only get problems if you don't understand what is happening.
I said: Don't use random push/pop. |
|||
![]() |
|
Roman
Quote: You only get problems if you don't understand what is happening. I understood, don't be angry. I try this in fasmw 1.73 : ;illegal local tmpReg:dword very fanny ;but compile ok if local tmpReg:DWORD Code: proc v2 local tmpReg:DWORD mov dword [tmpReg],eax Msg 'f' mov eax,[tmpReg] ret endp |
|||
![]() |
|
revolution
That is normal. What do you find "fanny"?
|
|||
![]() |
|
Ali.Z
Roman wrote: local tmpReg:dword because its defined in procXX.inc as upper case. _________________ Asm For Wise Humans |
|||
![]() |
|
Goto page Previous 1, 2, 3, 4, 5, 6 Next < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.
Website powered by rwasa.