The MASM Forum
General => The Campus => Topic started by: zedd151 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:
-
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 :
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
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 :
; ------------------------------------------------------
; 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
-
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?
-
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.
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
-
okay, got it. I think.
-
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.
-
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: