News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

VARARG in STDCALL mode

Started by jj2007, April 05, 2010, 01:07:56 AM

Previous topic - Next topic

jj2007

Here is a simple option to pass a variable number of args without using the C calling convention.
include \masm32\include\masm32rt.inc
include vararg.inc   ; vinv, vret, vloc, vargr, vargi

.code
s1 db "String 1", 0
s2 db "String 2", 0
s3 db "String 3", 0
s4 db "String 4", 0

start: print "Passing a variable # of args with STDCALL:"
vinv TestVarArgB, offset s1, offset s2, offset s3, offset s4
vinv TestVarArgB, offset s1, offset s2
exit

TestVarArgB proc ; NAKED proc, NO USES, NO ARGS!
vloc d1, d2:DWORD, r3:RECT, qw4:QWORD, ow5:OWORD, r4:REAL4  ; use locals as usual
mov ebx, vargct
print chr$(13, 10) ; the simplest usage, a repeat loop with vargr(reg32):
.Repeat
print vargr(ebx), 13, 10 ; vargREV or vargREG: print next arg
dec ebx ;  counting down restores correct order
.Until Zero?
print "The second arg was "
print vargi(2), 13, 10 ; vargi=vargImmediate
mov edx, vargct
vret edx ; vret allows to return one dword in eax
TestVarArgB endp

end start