flat assembler
Message board for the users of flat assembler.
Index
> Macroinstructions > [solved] fasmg proc64 differences when no parameters defined |
Author |
|
Tomasz Grysztar 21 Oct 2019, 11:08
Please take a look at the section of documentation that covers customizing procedures. If the standard prologue/epilogue macros do not do what you'd expect, you can alter them (see also this thread for a bit of history: https://board.flatassembler.net/topic.php?p=98814). The standard prologue for 64-bit Windows currently looks like this:
Code: macro prologuedef procname,flag,parmbytes,localbytes,reglist { local loc,fill,counter loc = (localbytes+15) and (not 15) parmbase@proc equ rbp+16 localbase@proc equ rbp-loc push rbp mov rbp,rsp if loc+fill sub rsp,loc+fill end if counter = 0 irps reg, reglist \{ push reg counter = counter+1 \} fill = 8*(counter and 1) } |
|||
21 Oct 2019, 11:08 |
|
Beege 22 Oct 2019, 01:50
Tomasz Grysztar wrote: But if you find that there is a bug there, please let us know. Thank you Tomasz. The code that macro produces from the original fasm vs the one in fasmg is where I ran into this and got confused. For that macro the input/output code I get is: Code: ;in proc _testfunc uses rbx ret endp ;out - 0x554889E54883EC08535BC9C3 0: 55 push rbp 1: 48 89 e5 mov rbp,rsp 4: 48 83 ec 08 sub rsp,0x8 8: 53 push rbx ; code..... 9: 5b pop rbx a: c9 leave b: c3 ret The current fasmg has a if parmbytes | localbytes Code: macro prologuedef procname,flag,parmbytes,localbytes,reglist local loc,fill loc = (localbytes+15) and (not 15) parmbase@proc equ rbp+16 localbase@proc equ rbp-loc if parmbytes | localbytes push rbp mov rbp,rsp if loc+fill sub rsp,loc+fill end if end if ... So for the same input I end up with: Code: 0: 53 push rbx 1: 5b pop rbx 2: c3 ret I use the fasmg.dll as part of a library for autoit to get some inline asm functionality (thread here) https://www.autoitscript.com/forum/topic/199758-flat-assembler-g-udf-with-x64/ and any time I want to call a function defined within my autoit script, the alignment has to be 16 byte or else I get a crash. So for this example if I put a fastcall in the body of that to another function in the script, I have to add the additional sub rsp, 8 instruction. On the other hand when I'm calling any function from windows api dlls like from kernel32, the alignment of rsp doesn't seem to matter. With or without the sub rsp, 8 - my script completes fine. So its seems I have some functions I need the alignment for and some I don't, but also a macro that may or may not define that alignment depending on if you have arguments. I add all that up in my head and feel like Im missing something I havent learned about yet. |
|||
22 Oct 2019, 01:50 |
|
Tomasz Grysztar 22 Oct 2019, 05:29
You're right, this macro has not been translated to fasmg properly. I'm uploading a correction.
|
|||
22 Oct 2019, 05:29 |
|
Beege 27 Oct 2019, 17:55
Tomasz Grysztar wrote: You're right, this macro has not been translated to fasmg properly. I'm uploading a correction. Thank you for updating this Tomasz. With that being the fix I believe the epiloguedef needs the same check removed. Code: macro epiloguedef procname,flag,parmbytes,localbytes,reglist match any, reglist iterate reg, reglist indx %%-%+1 pop reg end iterate end match if parmbytes | localbytes <----- leave end if retn end macro |
|||
27 Oct 2019, 17:55 |
|
Tomasz Grysztar 27 Oct 2019, 18:32
Thank you! I did not give this enough thought when uploading.
|
|||
27 Oct 2019, 18:32 |
|
Beege 27 Oct 2019, 21:33
Tomasz Grysztar wrote: Thank you! I did not give this enough thought when uploading. Your very welcome. Thanks for fasm in general! Sorry for the lack of clarity in my first post. I actually found a post by you that I believe is this exact same situation only it was from about 10 years ago and the orginal fasm so I told myself "that cant be my problem.. He fixed it 10 years ago". Im thinking now you either translated from an old copy or you have incredible consistency with the first drafts of macros. Cheers! https://board.flatassembler.net/topic.php?p=99833#99833 |
|||
27 Oct 2019, 21:33 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.