flat assembler
Message board for the users of flat assembler.
Index
> Windows > Tiny PE in win64Goto page Previous 1, 2, 3, 4 |
| Author |
|
|
revolution 19 Jul 2026, 17:59
The stack is not in the text section. "sub rsp,8" aligns the stack, not the code.
|
|||
|
|
Calendos 19 Jul 2026, 18:04
Thanks again. I'll think about your explanation.
|
|||
|
|
Calendos 20 Jul 2026, 17:44
Thank you for your contributions, which have helped me to better understand this alignment issue. Thank you also, bitRAKE, for clarifying the concepts involved. Consulting Microsoft's online documentation, I found an interesting reference in the article "Overview of x64 ABI conventions," the relevant section of which I've reproduced at the end of this message. This confirms that the stack is aligned to 4 bytes instead of 8. Hence, the corresponding action on RSP.
However, I still don't understand the alignment method that involves subtracting 8 from the RSP register (or the `push rbp` suggested by revolution). Personally, I would have preferred an instruction like: AND RSP,0FFFFFFFFFFFFFFF0 By doing so, we would truly align RSP to a QWord. From what I recall, I've never seen this kind of alignment practice in 64-bit MASM. But I have very little 64-bit programming experience. Could you recommend some reading material that would help me progress, if needed? Thank you in advance! Quote: Overview of x64 ABI conventions The text above is available at https://learn.microsoft.com/en-us/cpp/build/x64-software-conventions?view=msvc-170 |
|||
|
|
alCoPaUL 20 Jul 2026, 18:36
instead of messagebox, you can use printf and pass the output string through stdout & finally silently save it to a binary file, script or some kind of file format...
and still maintaining less than 1k byte size... _________________ Assembly Language Quines https://bitbucket.org/alcopavl/ia-64_quine/src/main/ https://bitbucket.org/alcopavl/x86x64/src/main/ https://github.com/alcopaul/beth_GviLLErMo_GIMO |
|||
|
|
bitRAKE 20 Jul 2026, 20:13
Calendos wrote: AND RSP,0FFFFFFFFFFFFFFF0 ExitProcess does not return. If that's the termination route of your application then the code doesn't even need to preserve non-volatile registers! The code can do POP REG -- not using the return and reuse caller's shadow-space. I like to use ENTER .frame, 0 -- just to save on code bytes, it's slower execution wise. AND RSP,-16 is only more valid when the stack value is unknown - like dynamic stack buffers. Let me know if you'd like an example - searching the board will no doubt return many from me. _________________ ¯\(°_o)/¯ AI may [not] have aided with the above reply. |
|||
|
|
revolution 20 Jul 2026, 23:41
Calendos wrote: However, I still don't understand the alignment method that involves subtracting 8 from the RSP register (or the `push rbp` suggested by revolution). Personally, I would have preferred an instruction like: Code: ; Inside the OS loader, that puts the program in memory ; here RSP is always aligned to 0 mod 16, as per the FASTCALL convention call [program_entry_point] ; address is in the PE header ; here RSP is now 8 mod 16, the return address was pushed onto the stack ; -------------------------------------------------------- ; now inside the program, the first instruction entry: push rbp ; (or sub rsp, 8 if preferred) ; here RSP is now 0 mod 16 again, proper alignment is guaranteed ; program does its thing here |
|||
|
|
AsmGuru62 24 Jul 2026, 00:32
The issue is that when Windows starts your program --- your aligned entry point is CALL-ed by Windows Loader.
Obviously a CALL instruction will put the return code into stack, misaligning it. 'text' section is aligned, of course. |
|||
|
| Goto page Previous 1, 2, 3, 4 < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2026, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.