Delphi uses the register calling convention which uses the eax, edx, ecx registers and the stack (left to right) (callee-routine cleans the stack)

what is the equivalent to the register convention that delphi uses in masm ?
thanks
Posted on 2003-07-13 01:55:32 by Jnrz
If you mean something that can be used with INVOKE, then the answer is 'there is no such thing in MASM'. AFAIK, none of MS compiler products uses such convention. So, it is only natural that MASM does not support it.
(Before your post, I did not know Borland adopted it. I thought Watcom was the only company using it.)
Posted on 2003-07-13 05:18:35 by Starless
You can always write your own macro for it, after all INVOKE is just a macro.
Posted on 2003-07-13 05:24:34 by donkey
masm doesn't support register calling conventions.
It doesn't support such thing as __fastcall calling conventions used by kernel mode routines.
In my KmdKit i use fastcall macro for __fastcall functions.

__fastcall
First two DWORD arguments are passed in ECX and EDX, the rest are passed right to left.
Called function pops its own arguments from the stack.




[size=9]
;:::::::::::::::::::::::::::::::::::::::::::::::

IFNDEF @ArgRev
@ArgRev MACRO arglist
LOCAL txt, arg
txt TEXTEQU <>
% FOR arg, <arglist>
txt CATSTR <arg>, <!,>, txt
ENDM
txt SUBSTR txt, 1, @SizeStr(%txt) - 1
txt CATSTR <!<>, txt, <!>>
EXITM txt
ENDM
ENDIF

;:::::::::::::::::::::::::::::::::::::::::::::::
;
; Added for supporting fastcall calling convention
;
; Usage Example:
; fastcall IofCompleteRequest, pIrp, IO_NO_INCREMENT
;
; addr is not supported
; offset is not supported for first and second param
; May be next time
;
;:::::::::::::::::::::::::::::::::::::::::::::::

fastcall MACRO api:REQ, p1, p2, px:VARARG

local arg, line, recx

recx = 0

IFNB <px>
% FOR arg, @ArgRev( <px> )
push arg
ENDM
ENDIF

IFNB <p1>
IF (OPATTR (p1)) AND 00010000y ;; Is a register value
IFDIFI <p1>, <ecx> ;; do not move ecx onto itself
mov ecx, p1
recx = 1 ;; no more ecx
ENDIF
ELSEIF (OPATTR (p1)) AND 00000100y ;; Is an immediate value
IF p1 EQ 0
xor ecx, ecx
ELSEIF p1 EQ 1
xor ecx, ecx
inc ecx
ELSEIF p1 EQ -1
or ecx, -1
ELSE
mov ecx, p1
recx = 1 ;; no more ecx
ENDIF
ELSE
mov ecx, p1
recx = 1 ;; no more ecx
ENDIF

IFNB <p2>
IF (OPATTR (p2)) AND 00010000y ;; Is a register value
IFIDNI <p2>, <ecx>
IF recx ;; if ecx was used report error
line TEXTEQU %@Line
% ECHO @FileCur(line) : ERROR! ECX register value overwritten by fastcall macro.
.ERR
ENDIF
ENDIF

IFDIFI <p2>, <edx> ;; do not move edx onto itself
mov edx, p2
ENDIF
ELSEIF (OPATTR (p2)) AND 00000100y ;; Is an immediate value
IF p2 EQ 0
xor edx, edx
ELSEIF p2 EQ 1
xor edx, edx
inc edx
ELSEIF p2 EQ -1
or edx, -1
ELSE
mov edx, p2
ENDIF
ELSE
mov edx, p2
ENDIF
ENDIF
ENDIF
call api
ENDM
[/size]
Posted on 2003-07-13 05:40:31 by Four-F