flat assembler
Message board for the users of flat assembler.
Index
> Macroinstructions > How about fast call convention ? I have macros... |
Author |
|
Blid 19 Apr 2007, 10:14
sorry ! error:
fcall MainF,ebx,ecx,esi,0,WIN32FINDDATA,ebx instead fcall MainF,eax,ecx,esi,0,6,ebx ; Blid |
|||
19 Apr 2007, 10:14 |
|
hidden 20 Apr 2007, 23:02
Quote: fcall MainF,ebx,ecx,esi,0,6,ebx result: Quote: mov eax, ebx Quote: mov eax, ebx Quote: fcall MainF,ebx,ecx,esi,edi,6,ebx |
|||
20 Apr 2007, 23:02 |
|
Blid 21 Apr 2007, 20:50
Thanks for you 1'st post!
Yes, it will be so. (I know it . It was a example (may be a litle ugly). Position of argument and register are know in fastcall (see macros). And then you send arguments to MainF, you know they positin in reg. Ofcourse 'invoke' (stdcall) more simple. You can push anything, (+ any oder)as you wish. But you code will be giant (very big) and slow. What is why i use my fcall macro. ; sorry, my eng. is poor |
|||
21 Apr 2007, 20:50 |
|
chris 27 Apr 2007, 03:10
here is my solution:
Code: macro fcall proc*,arg1,arg2,[arg] { common if ~arg1 eq if ~arg1 eq ecx mov ecx,arg1 end if if ~arg2 eq if ~arg2 eq edx mov edx,arg2 end if end if end if reverse pushd arg common call proc } macro finvoke proc*,arg1,arg2,[arg] { common if ~arg1 eq if ~arg1 eq ecx mov ecx,arg1 end if if ~arg2 eq if ~arg2 eq edx mov edx,arg2 end if end if end if reverse pushd arg common call [proc] } |
|||
27 Apr 2007, 03:10 |
|
Blid 08 May 2007, 17:22
it is a good idea.
Thanks for reply. Your macro very small, compact. But you are not using registers as it possible . You send two arg to function in registers, others will be store in memory. The instruction wich acsess to mem, using ebp as base has size 3 bytes (against mov reg32,reg32-2bytes) and slower by 5 times. That is my purpose. How about defining proc , using reg as var? Can you help my, i think it is good idea :--). |
|||
08 May 2007, 17:22 |
|
Blid 08 May 2007, 17:28
And you should use eax for arg! This more compact and faster.
But official documentation (i have it) about call conventions against eax. I do not anderstand. |
|||
08 May 2007, 17:28 |
|
Blid 01 Jul 2007, 10:23
Code: ;look at this macro - it more complex and powerfull macro qcall name*,arg1,arg2,arg3,arg4 { LoadArg eax,arg1 LoadArg ecx,arg2 LoadArg edx,arg3 LoadArg ebx,arg4 call name } macro LoadArg reg32*,arg { ; equ's ' 1 equ TRUE FALSE equ NULL 0 equ NULL if ~ arg eq ;process if arg if arg eq reg32 else if arg in <0,1,-1,NULL,TRUE,FALSE> xor reg32,reg32 if arg eq 1 inc reg32 end if if arg eq -1 dec reg32 end if else OptimC reg32,arg end if end if end if ;restore's ' restore 1 restore 0 restore FALSE } macro OptimC reg32,arg { if arg eqtype [0] if (arg eqtype 1) if (arg>-129)&(arg<127) push arg pop reg32 else mov reg32,arg end if else mov reg32,arg end if else if (arg eqtype 1) if (arg>-129)&(arg<127) push arg pop reg32 else mov reg32,arg end if else if arg eqtype EAX mov reg32,arg else lea reg32,[arg] end if end if end if } |
|||
01 Jul 2007, 10:23 |
|
Blid 01 Jul 2007, 10:26
Code: start: qcall xxx,start,129,[esi+eax],[esp] qcall xxx,[start],129,<esi+eax>,esp qcall xxx,eax,5,<esi+eax>,esp qcall xxx,2,esp,<esi+eax>,TRUE qcall xxx,FALSE,NULL,<esi+eax>,TRUE ;--------------------------disasm----------------------------------------- Code: .code:00401008 start: ; DATA XREF: .code:starto .code:00401008 ; .code:0040101Dr .code:00401008 mov eax, offset start .code:0040100D mov ecx, 81h .code:00401012 mov edx, [esi+eax] .code:00401015 mov ebx, [esp] .code:00401018 call sub_401000 .code:0040101D mov eax, dword ptr start .code:00401022 mov ecx, 81h .code:00401027 lea edx, [esi+eax] .code:0040102A mov ebx, esp .code:0040102C call sub_401000 .code:00401031 push 5 .code:00401033 pop ecx .code:00401034 lea edx, [esi+eax] .code:00401037 mov ebx, esp .code:00401039 call sub_401000 .code:0040103E push 2 .code:00401040 pop eax .code:00401041 mov ecx, esp .code:00401043 lea edx, [esi+eax] .code:00401046 xor ebx, ebx .code:00401048 inc ebx .code:00401049 call sub_401000 .code:0040104E xor eax, eax .code:00401050 xor ecx, ecx .code:00401052 lea edx, [esi+eax] .code:00401055 xor ebx, ebx .code:00401057 inc ebx .code:00401058 call sub_401000 |
|||
01 Jul 2007, 10:26 |
|
Blid 01 Jul 2007, 10:28
;all are optimized by size
|
|||
01 Jul 2007, 10:28 |
|
Blid 05 Aug 2007, 20:10
this next step:
Code: Arguments = 1 macro Arguments name,reg1,reg2,reg3,reg4 { if ~reg1 eq name#.argum1 equ reg1 end if if ~reg2 eq name#.argum2 equ reg2 end if if ~reg3 eq name#.argum3 equ reg3 end if if ~reg4 eq name#.argum4 equ reg4 end if } ;example Code: memset equ memfil proc memfil stdcall uses edi ;arg : (buff,char,size) if (defined Arguments)&(Arguments=1) Arguments memfil, edx,\;edx pointer to memory al,\ ;eax (al) char to fill ecx ;ecx size to fill end if ;return: eax=pointer to memory push edx mov edi,edx mov ah,al ;eax = multipl copy of al ror eax,8 mov ah,al ror eax,8 mov ah,al push ecx shr ecx,2 rep stosd pop ecx and ecx,3 rep stosb pop eax ;return pointer to buff ret endp ;code: qcall memfil,3,dwBuffer,5*4 ;will be: Code: mov edx,dwBuffer mov al,3 mov ecx,5*4 call memfil |
|||
05 Aug 2007, 20:10 |
|
Blid 05 Aug 2007, 20:12
this next step:
Code: Arguments = 1 macro Arguments name,reg1,reg2,reg3,reg4 { if ~reg1 eq name#.argum1 equ reg1 end if if ~reg2 eq name#.argum2 equ reg2 end if if ~reg3 eq name#.argum3 equ reg3 end if if ~reg4 eq name#.argum4 equ reg4 end if } ;example Code: memset equ memfil proc memfil stdcall uses edi ;arg : (buff,char,size) if (defined Arguments)&(Arguments=1) Arguments memfil, edx,\;edx pointer to memory al,\ ;eax (al) char to fill ecx ;ecx size to fill end if ;return: eax=pointer to memory push edx mov edi,edx mov ah,al ;eax = multipl copy of al ror eax,8 mov ah,al ror eax,8 mov ah,al push ecx shr ecx,2 rep stosd pop ecx and ecx,3 rep stosb pop eax ;return pointer to buff ret endp ;code: qcall memfil,3,dwBuffer,5*4 ;will be: Code: mov edx,dwBuffer mov al,3 mov ecx,5*4 call memfil |
|||
05 Aug 2007, 20:12 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.