flat assembler
Message board for the users of flat assembler.
Index
> Macroinstructions > [sug] Yet another PROC macro suggestion for freeing up EBP Goto page 1, 2 Next |
Would you like to integrate an ESP base proc macro into fasm? | |||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||
Total Votes : 29 |
Author |
|
LocoDelAssembly 01 Oct 2006, 13:48
I voted the first entry, however, I wish to see invoke, stdcall, and all that working without doing adjustments by my own. Do you think that it's possible or there is some limitation here that prevents automatic stack address adjustment?
|
|||
01 Oct 2006, 13:48 |
|
revolution 01 Oct 2006, 14:11
Quote: I wish to see invoke, stdcall, and all that working without doing adjustments by my own. Do you think that it's possible or there is some limitation here that prevents automatic stack address adjustment? |
|||
01 Oct 2006, 14:11 |
|
okasvi 01 Oct 2006, 20:00
I'm sure Tomasz could make us proc macro using esp w/adjusting push/pop/call/invoke/stdcall etc. that would work in most cases
I think the problem is that he doesnt want to add anything which wont work in all cases |
|||
01 Oct 2006, 20:00 |
|
vid 01 Oct 2006, 21:52
i like it as idea, and i think tomasz already had such macros for 64 things. maybe not that complete.
but i am afraid it misses point on cases when it should be used: Code: 1) The extra register makes some alogrithms really fly. 2) Leaf procedures, or simple functions, that don't require the extra overhead of EBP base setup, saves code size and execution time. |
|||
01 Oct 2006, 21:52 |
|
revolution 01 Oct 2006, 22:47
vid wrote: both are things that should be done by hand, and then they are done better than with macros, when it is really important Code: if used crc32_byte_raw crc32_byte_raw: virtual at esp .ret dd ? .crc dd ? .bite dd ? .polynomial dd ? end virtual mov eax,[.crc] not eax xor al,byte[.bite] mov edx,8 .a: shr eax,1 sbb ecx,ecx and ecx,[.polynomial] xor eax,ecx dec edx jnz .a not eax ret end if |
|||
01 Oct 2006, 22:47 |
|
Borsuc 05 Oct 2006, 10:07
What's so bad about the tiny details? You can add them after you design your algorithm. However I do agree that repeating the same code in a source code tends to be better replaced by macros
|
|||
05 Oct 2006, 10:07 |
|
vid 05 Oct 2006, 11:19
revolution: also it makes it too easy to make error too hard to find
|
|||
05 Oct 2006, 11:19 |
|
MazeGen 05 Oct 2006, 12:16
revolution: Petroizki (from MASM board) and me already made the same thing in MASM (called "pmacros"). I attach the latest help file which I'm aware of, maybe it can help you somehow.
|
|||||||||||
05 Oct 2006, 12:16 |
|
vid 05 Oct 2006, 13:09
rev: maybe you could disable esp for that part of source, and enable it later:
Code: _internal_esp equ esp esp equ ___undefined___symbol___ ;and internally in your macros, you will use _internal_esp, user ;can't access esp directly. same for push/pop restore _internal_esp restore esp |
|||
05 Oct 2006, 13:09 |
|
revolution 05 Oct 2006, 20:21
Quote: maybe you could disable esp for that part of source, and enable it later: I don't imagine that using the esp proc will become the default, more likely something like 10% of procs can benefit from it. Even the current proc macro has problems when using push/pop but people either don't notice or don't understand why it is a problem. |
|||
05 Oct 2006, 20:21 |
|
vid 06 Oct 2006, 06:06
what problems does current proc macro have? you say that this wouldnt work??
Code: proc a uses ebx mov ebx, 123 push eax ret endp |
|||
06 Oct 2006, 06:06 |
|
revolution 06 Oct 2006, 11:42
vid' wrote: what problems does current proc macro have? Code: proc b uses ebx ,val mov ebx, 123 push eax ret endp Code: ;00401021 55 PUSH EBP ;00401022 89E5 MOV EBP,ESP ;00401024 53 PUSH EBX ;00401025 BB 7B000000 MOV EBX,7B ;0040102A 50 PUSH EAX ;0040102B 5B POP EBX ;0040102C C9 LEAVE ;0040102D C2 0400 RETN 4 Now with the macro I posted above it assembles to this: Code: ;00401021 53 PUSH EBX ;00401022 55 PUSH EBP ;00401023 89E5 MOV EBP,ESP ;00401025 BB 7B000000 MOV EBX,7B ;0040102A 50 PUSH EAX ;0040102B C9 LEAVE ;0040102C 5B POP EBX ;0040102D C2 0400 RETN 4 Okay, now back to the code you posted. It assembles to this: Code: ;00401011 53 PUSH EBX ;00401012 BB 7B000000 MOV EBX,7B ;00401017 50 PUSH EAX ;00401018 5B POP EBX ;00401019 C3 RETN |
|||
06 Oct 2006, 11:42 |
|
vid 06 Oct 2006, 11:45
it was REALLY done that way
i didn't even bothered to try it... wouldn't believe eh-eh... tomasz, tomasz |
|||
06 Oct 2006, 11:45 |
|
vid 06 Oct 2006, 11:47
btw, what was the reason of "uses ebx ecx" if this wasn't supported?
|
|||
06 Oct 2006, 11:47 |
|
revolution 06 Oct 2006, 11:54
Quote: btw, what was the reason of "uses ebx ecx" if this wasn't supported? |
|||
06 Oct 2006, 11:54 |
|
UCM 06 Oct 2006, 22:13
Well, if it is missing a pop, then there is an error
|
|||
06 Oct 2006, 22:13 |
|
revolution 07 Oct 2006, 11:25
okasvi wrote: I'm sure Tomasz could make us proc macro using esp w/adjusting push/pop/call/invoke/stdcall etc. Code: proc abc esp uses ebx, foo ;... call .subFunction1 call .subFunction2 ;... ret .subFunction1: mov eax,[foo] ;what offset goes here for foo? ;... retn .subFunction2: mov eax,[foo] ;what offset goes here for foo? ;... call .subFunction1 ;... retn endp Inside subFunction2, above, the foo offset can be predicted (+4) for the function as shown. But inside subFunction1 there is no value that can reliably be used for foo. subFunction1 is called from two places and with different stack offsets in effect. There is no solution to this problem unless we do some modifcation like inseting a dummy push before the call to subFunction1 within the main body of abc (and later a pop of course). But such a solution is incredibly easy to get wrong during the next editing session. And any macro solution would be incredibly complex and hard to get correct. And that is just a simple example! This is why I think it is best to not do such a thing and therefore force the programmer to take responsibilty for stack usage. If the programmer does not know how to manage the stack then the easiest solution is to delete the "esp" declaration and the problem is solved. This is why I made sure to initially post some reasons not to use esp based procedures, because they are very easy to get wrong. The addition of esp functionality is not intended to be normal usage, just where it can be useful and simple to apply. |
|||
07 Oct 2006, 11:25 |
|
revolution 07 Oct 2006, 11:29
MazeGen wrote: Petroizki (from MASM board) and me already made the same thing in MASM (called "pmacros"). I attach the latest help file which I'm aware of, maybe it can help you somehow. |
|||
07 Oct 2006, 11:29 |
|
revolution 07 Oct 2006, 11:34
UCM wrote: Well, if it is missing a pop, then there is an error 1) Code: proc abc uses ebx, foo ;... call .f1 ;... .err ret .f1: invoke something,1,2,3 test eax,eax jz .err ;... retn endp Code: proc abc uses ebx, foo ;... push ecx invoke something,1,2,3 test eax,eax jz .err ;... pop ecx ;... .err ret endp |
|||
07 Oct 2006, 11:34 |
|
Goto page 1, 2 Next < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.