Here is a printf implementation similar to the inlined version of the latest MS VC releases :
.386
.model flat,stdcall
option casemap:none
ExitProcess PROTO :DWORD
__p__iob PROTO C
vfprintf PROTO C :DWORD,:DWORD,:VARARG
printf PROTO C :DWORD,:VARARG
includelib kernel32.lib
includelib msvcrt.lib
_iobuf STRUCT
_ptr DWORD ?
_cnt DWORD ?
_base DWORD ?
_flag DWORD ?
_file DWORD ?
_charbuf DWORD ?
_bufsiz DWORD ?
_tmpfname DWORD ?
_iobuf ENDS
FILE TYPEDEF _iobuf
.data
pi real8 3.141592
format db '%s is nearly equal to %f',0
str1 db 'Pi',0
.code
start:
invoke printf,ADDR format,ADDR str1,pi
invoke ExitProcess,0
printf PROC C _format:DWORD,args:VARARG
invoke __p__iob
; #define stdout (&__iob_func()[1])
add eax,SIZEOF(FILE)
lea ecx,args
invoke vfprintf,eax,_format,ecx
ret
printf ENDP
END start
The Universal C run-time version :
int __cdecl __stdio_common_vfprintf(unsigned __int64 _Options, FILE* _Stream, char const* _Format , int _Locale, va_list);
int printf(const char * format, ...)
{
int retVal;
va_list vl;
va_start(vl, format);
retVal = __stdio_common_vfprintf(0, _stdout,format, 0, vl);
va_end(vl);
return retVal;
}