News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Prototype bug and API implementation

Started by LiaoMi, May 25, 2020, 09:11:58 PM

Previous topic - Next topic

nidud

#15
deleted

Vortex

Hi nidud,

Thanks for explaining Watcall, I didn't knew this calling convention.

QuoteWatcall is FASTCALL using EAX, ECX, EDX, and EBX

Regarding Watcall, the fifth and the further parameters are passed to the stack, is that correct? Another variant of my custom invoke macro could handle Watcall.

Edit :

QuoteWatcom compiler

The Watcom compiler doesn't conform to the register usage conventions in table 4. The
only scratch register is EAX. All other general purpose registers are callee-save, except for
EBX, ECX, EDX when used for parameter transfer, and ESI when used for return pointer. (In
16-bit mode, ES is also a scratch register). It is possible to specify any other register usage
by the use of pragmas in the Watcom compiler.

https://www.agner.org/optimize/calling_conventions.pdf

nidud

#17
deleted

Vortex

Hi nidud,

QuoteI haven't  "released" any of these FASTCALL conventions in 32-bit as done in 64.

Maybe I am missing something, Asmc supports the standard fastcall convention in 32-bit :

; Source code assembled with
; Asmc Macro Assembler Version 2.31.30

.386
.model flat,stdcall
option casemap:none

includelib "\asmc-master\lib\kernel32.lib"
includelib "\asmc-master\lib\msvcrt.lib"

ExitProcess PROTO :DWORD
printf PROTO C :DWORD,:VARARG

.data
string1     db '10 + 20 + 30 + 40 = %d',0

.code

fcallproc PROC FASTCALL a:DWORD,b:DWORD,c:DWORD,d:DWORD

    mov     eax,a
    add     eax,b
    add     eax,c
    add     eax,d
    ret

fcallproc ENDP

start:

    invoke  fcallproc,10,20,30,40
    invoke  printf,ADDR string1,eax
    invoke  ExitProcess,0
   
END start


Disassembling the object module :
_text   SEGMENT DWORD PUBLIC 'CODE'

@fcallproc@16 PROC NEAR
        push    ebp
        mov     ebp, esp
        mov     eax, ecx
        add     eax, edx
        add     eax, dword ptr [ebp+8H]
        add     eax, dword ptr [ebp+0CH]
        leave
        ret     8
@fcallproc@16 ENDP

_start  PROC NEAR
        push    40
        push    30
        mov     edx, 20
        mov     ecx, 10
        call    @fcallproc@16
        push    eax
        push    offset _string1
        call    _printf
        add     esp, 8
        push    0
        call    _ExitProcess@4
_start  ENDP

_text   ENDS

nidud

#19
deleted