flat assembler
Message board for the users of flat assembler.
Index
> Tutorials and Examples > Video Tutorial/Demonstration Goto page Previous 1, 2 |
Author |
|
revolution 19 May 2014, 10:33
m3ntal wrote: With one parameter, it would always do the same: call f. Code: call GetTickCount ;... GetTickCount: jmp [DLLEntryGetTickCount] DLLEntryGetTickCount dd DLLFunction Code: call [GetTickCount] ;... GetTickCount dd DLLFunction |
|||
19 May 2014, 10:33 |
|
m3ntal 19 May 2014, 11:23
The call macro needs to know linking information, not the caller. We only have to know function name and parameters.
Even if there is a situation where you'd want to specify convention, the fastcall/stdcall/invoke/cinvoke/etc macros would still be valid with the call extension that selects the prefix. |
|||
19 May 2014, 11:23 |
|
m3ntal 19 May 2014, 11:48
Code: convention 's' ; set standard stdcall convention |
|||
19 May 2014, 11:48 |
|
revolution 19 May 2014, 13:23
m3ntal wrote:
When a program links to disparate libraries there is a need to use different conventions at different times. For example DLLs like zlib and msvcrt use C-call, but the Windows API uses stdcall. If one intersperses calls to the API and other calls to zlib we have to also remember to switch calling conventions before making each call. I find this type of thing, where we need to rely upon an external global state, to get the correct instructions to be confusing and prone to making easy errors. If I copy and paste a body of code into another place that has been set to use a different convention then I get incorrect code. Your proposal of relying upon some unseen type information has the problem of R2L and L2R difficulties. While we can write a macro in such a way to avoid such things by producing extra corrective code I think this is the wrong solution. Instead the programmer could rewrite to match the convention functionality, and thus offering better opportunities to optimise and control the code generation. I would be fine with a macro named docall (or anything other than call) that does all the magic calling tricks and whatnot. But naming his do-everything macro as "call" adds a layer of abstraction (and equivalent layers of obscurity and confusion) to code. |
|||
19 May 2014, 13:23 |
|
m3ntal 19 May 2014, 16:41
Quote: we have to also remember to switch calling conventions before making each call... Quote: Instead the programmer could rewrite to match the convention functionality, and thus offering better opportunities to optimise and control the code generation. Quote: I would be fine with a macro named docall (or anything other than call) that does all the magic calling tricks and whatnot. But naming his do-everything macro as "call" adds a layer of abstraction (and equivalent layers of obscurity and confusion) to code. All this time I wasted talking about it, I could've wrote one good call macro that's compatible with FASM's proc+imports. |
|||
19 May 2014, 16:41 |
|
sid123 20 May 2014, 08:46
Guys, can we shift this discussion? The topic title is entirely different from what's being discussed....
|
|||
20 May 2014, 08:46 |
|
edfed 20 May 2014, 09:55
yep, calling convention is the main feature of any langage. and the topic is gentlly deviating from it's initial subject. i wonder how many post before "johnfound is dumbass" will be writen
answer, 6, 6 = 4+2, then, 42, the answer! |
|||
20 May 2014, 09:55 |
|
revolution 20 May 2014, 13:53
sid123 wrote: Guys, can we shift this discussion? The topic title is entirely different from what's being discussed.... |
|||
20 May 2014, 13:53 |
|
m3ntal 21 May 2014, 03:11
sid123: Just wanted to inspire users to create videos. zhak and John changed the subject to language. call/import pertains to language/semantics: call f, a, b, c. I wouldn't have responded if no one else did.
edfed: "X is a dumbass"? All humans are intelligent in some ways and stupid in other ways. |
|||
21 May 2014, 03:11 |
|
m3ntal 21 May 2014, 04:44
Universal call is working. call has been successfully extended/upgraded and maintains its original meaning:
Code: call my.proc, a, b, c ; stdcall (proc) call ExitProcess, 0 ; invoke (import 'i') call strcpy, a, b ; cinvoke (import 'c') call l ; call (label) call eax ; call call [eax+ecx*4] ; call Code: macro call f, [p] { common local c c=0 match a b, f ; 2+ tokens in \{ c=1 \} ; name? use call if c=0 ; else if defined f#.$C$ ; convention? if f#.$C$='s' ; select... stdcall f, p else if f#.$C$='i' invoke f, p else if f#.$C$='C' ccall f, p else if f#.$C$='c' cinvoke f, p else if f#.$C$='v' ; variadic callv f, p end if else ; no convention. c=1 ; use call end if end if if c=1 ; use call? call dword f end if } ; import library. RVAs of dll names and ; tables, ending with 20 zero bytes macro library [names] { forward dd 0,0,0,\ RVA names#_name, RVA names#_table common dd 0,0,0,0,0 } ; import functions from dll. c=convention 'c' ; DLL name + import RVA table. each table ends ; with 0. finally, import names. dw 0 is ; "ordinal" (N/A) macro import c, dll, [names] { common dll#_name \ ; text dll_name='DLL.DLL' db `dll#'.DLL', 0 dll#_table: ; dll_table: forward names#.$C$=c ; convention if used names names \ dd RVA _#names ; import name RVAs end if common dd 0 ; end forward if used names _#names dw 0 ; import names db `names, 0 ; 'import' end if } ; example usage: data import library KERNEL32, USER32, SHELL32, MSVCRT import 'i', KERNEL32, ExitProcess import 'i', USER32, MessageBoxA, wsprintfA import 'i', SHELL32, ShellExecuteA import 'c', MSVCRT, strlen, strcpy, strcat end data Last edited by m3ntal on 22 May 2014, 03:30; edited 1 time in total |
|||
21 May 2014, 04:44 |
|
m3ntal 22 May 2014, 03:25
Universal call, proc, import + example
|
|||||||||||
22 May 2014, 03:25 |
|
revolution 22 May 2014, 03:42
What happens for:
Code: call wsprintf,dest,'%u',1 |
|||
22 May 2014, 03:42 |
|
m3ntal 22 May 2014, 03:52
Error, import uses exact names: wsprintfA. See EXAMPLE.ASM. That's just an example import table. I forgot which convention wsprintfA uses.
|
|||
22 May 2014, 03:52 |
|
Goto page Previous 1, 2 < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.