Author Topic: Prototype bug and API implementation  (Read 5695 times)

nidud

  • Member
  • *****
  • Posts: 2388
    • https://github.com/nidud/asmc
Re: Prototype bug and API implementation
« Reply #15 on: May 26, 2020, 11:36:06 PM »
deleted
« Last Edit: February 26, 2022, 03:52:56 AM by nidud »

Vortex

  • Member
  • *****
  • Posts: 2794
Re: Prototype bug and API implementation
« Reply #16 on: May 27, 2020, 12:00:26 AM »
Hi nidud,

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

Quote
Watcall 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 :

Quote
Watcom 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

  • Member
  • *****
  • Posts: 2388
    • https://github.com/nidud/asmc
Re: Prototype bug and API implementation
« Reply #17 on: May 27, 2020, 12:55:54 AM »
deleted
« Last Edit: February 26, 2022, 03:53:07 AM by nidud »

Vortex

  • Member
  • *****
  • Posts: 2794
Re: Prototype bug and API implementation
« Reply #18 on: May 27, 2020, 01:31:45 AM »
Hi nidud,

Quote
I 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 :

Code: [Select]
; 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 :
Code: [Select]
_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

  • Member
  • *****
  • Posts: 2388
    • https://github.com/nidud/asmc
Re: Prototype bug and API implementation
« Reply #19 on: May 27, 2020, 03:02:28 AM »
deleted
« Last Edit: February 26, 2022, 03:53:20 AM by nidud »