Author Topic: Why 'rcall' and 'invoke' ?  (Read 606 times)

zedd151

  • Member
  • *****
  • Posts: 1957
Why 'rcall' and 'invoke' ?
« on: December 06, 2022, 05:24:58 AM »
To the casual user they both seem to do the same thing, and rv() for that matter. So, what's the difference between them? I am not very fluent in the ways of 64 bit masm coding btw, so forgive if it seems a silly question.


Whoops! "rcall" is similar to "invoke". Why those two different macros? I was confused briefly by the similar names (rcall and rvcall). Topic title changed... (previously "Why rcall and rvcall" in error)
If 'rcall' does essentially the same thing as 'invoke', why bother with it?

rv() and rvcall() both return value in eax and rax respectively - are 32 and 64 bit versions of same macro? Or is that wrong?  :greensml:
Regards, zedd.
:tongue:

Vortex

  • Member
  • *****
  • Posts: 2788
Re: Why 'rcall' and 'invoke' ?
« Reply #1 on: December 06, 2022, 06:08:25 AM »
Hi zedd,

The rvcall macro is specific to Masm64 and takes a maximum of 4 parameters. Commenting out the lines 16 and 17 will produce an error message :

Code: [Select]
include \masm64\include64\masm64rt.inc

.data

buffer  db 128 dup(?)

str1    db '2 + 4 + 6 + 8 + 10 = %u',0

.code

entry_point PROC

    invoke  wsprintf,ADDR buffer,ADDR str1,\
            rv(sum,2,4,6,8,10)

   ; invoke wsprintf,ADDR buffer,ADDR str1,\
   ;        rvcall(sum,2,4,6,8,10)

    invoke  StdOut,ADDR buffer

    ret
   

entry_point ENDP

sum PROC a:QWORD,b:QWORD,c:QWORD,d:QWORD,e:QWORD

    mov     rax,a
    add     rax,b
    add     rax,c
    add     rax,d
    add     rax,e
    ret

sum ENDP

END

Code: [Select]
G:\masm64>\masm64\bin64\ml64.exe /c rvSample.asm
Microsoft (R) Macro Assembler (x64) Version 10.00.40219.01
Copyright (C) Microsoft Corporation.  All rights reserved.

 Assembling: rvSample.asm

    ********************************************
    argument limit of 4 exceeded in procedure -> sum
    use the 'rv()' notation instead of 'rvcall'
    ********************************************

The difference is that the rvcall macro is based on the register_call macro optimized for 4 parameters :

 
Code: [Select]
; ------------------------------------------------------
  ; register call for procedures that have 4 or less
  ; arguments while avoiding the HLL shadow space overhead
  ; ------------------------------------------------------
    register_call MACRO pname,ag1,ag2,ag3,ag4

zedd151

  • Member
  • *****
  • Posts: 1957
Re: Why 'rcall' and 'invoke' ?
« Reply #2 on: December 06, 2022, 07:38:43 AM »
Thanks vortex for the clarification.  :thup:   I thought that rvcall() == rv(); but rvcall() for 64 bit and rv() for 32 bit.


And rcall vs invoke?
Regards, zedd.
:tongue:

Vortex

  • Member
  • *****
  • Posts: 2788
Re: Why 'rcall' and 'invoke' ?
« Reply #3 on: December 06, 2022, 08:01:37 AM »
Hi zedd,

rcall is useful to call functions taking a maximum of 4 parameters. The invoke does not have this limit. The rcall macro should be faster than invoke with the condition that you don't exceed the limit.

Code: [Select]
    rcall MACRO pname,ag1,ag2,ag3,ag4,ag5

      IFNB <ag5>
        % echo     
        % echo     ********************************************
        % echo     argument limit of 4 exceeded in procedure -> pname
        % echo     use the 'invoke' notation instead of 'rcall'
        % echo     ********************************************
        % echo     
        goto rcallexit
      ENDIF

      register_call pname,ag1,ag2,ag3,ag4

      :rcallexit
    ENDM

zedd151

  • Member
  • *****
  • Posts: 1957
Re: Why 'rcall' and 'invoke' ?
« Reply #4 on: December 06, 2022, 08:05:16 AM »
okay, got it. I think.
Regards, zedd.
:tongue:

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 10583
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: Why 'rcall' and 'invoke' ?
« Reply #5 on: December 06, 2022, 08:32:34 AM »
Hi Z,

Erol has said it all. The difference is that with rcall and rvcall is they will only accept QWORD size arguments up to a maximum of 4 which match the Win 64 FASTCALL format of 4 registers, rcx, rdx, r8 and r9.

The "invoke" macro is far more flexible in that it will take up to 24 arguments and will handle different data sizes from BYTE up to QWORD. Any larger and you pass in larger registers OR you pass by the address of larger data.

With system functions, a large number take 4 or less arguments and rcall and rvcall are more efficient but with higher argument counts, invoke has many advantages.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

zedd151

  • Member
  • *****
  • Posts: 1957
Re: Why 'rcall' and 'invoke' ?
« Reply #6 on: December 06, 2022, 08:35:45 AM »
So rcall and rvcall() are register based, for four arguments or less? Okay. This clarifies further thanks. I may yet start really coding in 64 bit Masm, rather than just half assed converting from 32 bit code.  :biggrin:
Regards, zedd.
:tongue: