Testproc.asm (with the test code components commented out):
;==============================================================================
;include \masm32\include\masm32rt.inc
.386
.model flat,stdcall
;==============================================================================
.data
.code
;==============================================================================
;-----------------------------------------------------------------------------
; This derived from an old 16-bit example in the MASM 6.0 Programmer's Guide.
;
; The code prefixed with ";;" is generated by MASM, included here to show
; what the default prologue and epilogue are adding to the procedure.
;-----------------------------------------------------------------------------
addup proc C argCount:DWORD, args:VARARG
;;push ebp
;;mov ebp, esp
xor eax, eax ; zero work reg
xor edx, edx ; zero arg index
mov ecx, argCount
test ecx, ecx
jnz @F
;;leave
ret ; return if zero args
@@:
add eax, args[edx*4] ; add eax,[ebp+edx*4+12]
add edx, 1 ; adjust to next arg
sub ecx, 1
jnz @B
;;leave
ret
addup endp
;==============================================================================
start:
;==============================================================================
comment |
invoke addup, 0
printf("%d\n", eax )
invoke addup, 1, 1
printf("%d\n", eax )
invoke addup, 2, 1, 2
printf("%d\n", eax )
invoke addup, 3, 1, 2, 3
printf("%d\n", eax )
invoke addup, 4, 1, 2, 3, 4
printf("%d\n", eax )
inkey
exit
|
;==============================================================================
;end start
end
test.c:
#include <windows.h>
#include <conio.h>
#include <stdio.h>
extern int addup(int argCount, ... );
int main( void )
{
printf("%d\n",addup(0));
printf("%d\n",addup(1,1));
printf("%d\n",addup(2,1,2));
printf("%d\n",addup(3,1,2,3));
printf("%d\n",addup(4,1,2,3,4));
getch();
}
And the batch file that I used to compile:
set file="test"
set PATH=C:\Program Files\Microsoft Visual C++ Toolkit 2003\bin;%PATH%
set INCLUDE=C:\Program Files\Microsoft SDK\include;C:\Program Files\Microsoft Visual C++ Toolkit 2003\include;%INCLUDE%
set LIB=C:\Program Files\Microsoft SDK\Lib;C:\Program Files\Microsoft Visual C++ Toolkit 2003\lib;%LIB%
cl /W4 /FA %file%.c testproc.obj
pause