flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
LocoDelAssembly 21 Aug 2006, 01:54
invoke function, addr localVar, ...
[edit] http://flatassembler.net/docs.php?article=win32 wrote: 2.1 Procedure parameters |
|||
![]() |
|
daluca 21 Aug 2006, 19:56
thanks: i don't know how could I miss that part of the documentation.
|
|||
![]() |
|
vid 21 Aug 2006, 20:11
when we got to this, i have currently implemented saving of such used register in FASMLIB "libcall" macro:
Code: mov [eaxsave], eax lea eax, [ebp-100h] push eax mov eax, [eaxsave] call [RegisterClass] so you can use something like this: Code: libcall proc, eax, edx, addr something but now i find it somewhat superstitious, and too much slowing when almost never needed. i think i could change behavior to stop compilation with error, when EAX is used after being modified with "addr". Same behavior is already implemented with nested calls, which return value in eax. For example this code throws error: Code: libcall 1, eax, <libcall something, 1, 2>, 3 Or maybe i could optimize eax-saving code to something like this, even with nested calls: Code: push eax lea eax, [ebp+100h] xchg eax, [esp] seems a fairly good idea, what do you think? |
|||
![]() |
|
Tomasz Grysztar 21 Aug 2006, 20:13
It's a good one.
|
|||
![]() |
|
vid 21 Aug 2006, 20:20
or best possibility, to use this code only when needed... but this becomes quite hard to code with nested calls, and also it will slow down preprocessing, noticeably, i afraid.
[edit]as thinking about it, the stress could be moved to assembly stage, with some forward-referencing. I think this possiblity could be better |
|||
![]() |
|
dead_body 22 Aug 2006, 07:01
the idea is very interesting.
|
|||
![]() |
|
MazeGen 22 Aug 2006, 09:24
Code: xchg reg, mem Code: xor eax, [esp] xor [esp], eax xor eax, [esp] but it would obfuscate the code too much I think. I prefer raising an error in my macros so the user has to pass the parameter in another register. |
|||
![]() |
|
Tomasz Grysztar 22 Aug 2006, 10:02
Any API call is anyway most probably slow enough that this wouldn't do much difference - while it is clear and safe solution. If you want it to be fast, you shouldn't use macros in the first place.
![]() OK, just my personal opinion. |
|||
![]() |
|
MazeGen 22 Aug 2006, 10:10
I was rather hinting at the fact that vid says this code
Code: mov [eaxsave], eax lea eax, [ebp-100h] push eax mov eax, [eaxsave] call [RegisterClass] is "too much slowing" and this code Code: push eax lea eax, [ebp+100h] xchg eax, [esp] is its optimized version. |
|||
![]() |
|
vid 22 Aug 2006, 10:26
and i am not going to use this only for api calls
![]() |
|||
![]() |
|
Tomasz Grysztar 22 Aug 2006, 10:50
Nevertheless I feel tempted to make it this way in fasm's extended headers. It's really nice and clear way of avoiding problems with register conflicts for "addr" prefix and nested calls (which are still the "extended" features to be used to have clear and easy code rather than the fast one).
|
|||
![]() |
|
vid 22 Aug 2006, 11:11
you want to do it always this way, or only when it is nescesary? because finding out when it is nescessary will produce quite heavy load on either preprocessor (this way also the macros become much uglier), or on assembler (macros remain nice, but there will be some forward referencing and conditioning for each such argument)
or maybe there is way i didn't find out |
|||
![]() |
|
Tomasz Grysztar 22 Aug 2006, 11:14
Always - I think it's just nice.
![]() |
|||
![]() |
|
daluca 22 Aug 2006, 22:01
How about this:
Code: lea ebp,[ebp-100h] ;mov reg,ebp ;push ebp lea ebp,[ebp+100h] or maybe just: Code: sub ebp,100h ;mov reg,ebp ;push ebp add ebp,100h |
|||
![]() |
|
vid 22 Aug 2006, 22:44
daluca:
![]() i believe you got something wrong |
|||
![]() |
|
UCM 23 Aug 2006, 00:13
daluca: That would work (in fact nicer solution:
Code: push ebp sub [esp],100h |
|||
![]() |
|
daluca 23 Aug 2006, 05:32
yes i got it wrong:
Code: lea ebp,[ebp-100h] mov eax,ebp lea ebp,[ebp+100h] is a redundance of: lea eax,[ebp-100h] I just thought addr could be use like: Code:
mov eax,addr wc
and about: Code: lea ebp,[ebp-100h] push ebp lea ebp,[ebp+100h] well is just a way to push the offset of a local variable without the use of any other register and the diference between the two leas is just the sign, i thought maybe this fact could be usefull in the macro implementation. sorry: macros are realy not my field although the UCM solution is indeed nicer. but I only have one doubt: Code: addr 5*2+1000 why would you refer to the offset of a local variable in that way? |
|||
![]() |
|
Tomasz Grysztar 23 Aug 2006, 08:32
First: you cannot assume that EBP is the stack frame pointer, in fact you cannot assume it has any given value (myself I often use EBP for different purposes - with so few registers in x86 it's sometimes inavoidable).
Second: you cannot assume "addr" is used just for local variables and procedure arguments. This may be even "ebx+ecx*2+100h" address. |
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.