In order to learn the smooth progress, today try to review the C and assembly language Joint compilation. The code is simple:
/* main.c */extern void Print1 (), char strformat[] = "x =%d, y =%d, x + y =%d"; int main () {Print1 (); return 0;}
; Proc.nasextern printfextern strformatglobal print1[section. DATA]NX DD 14nY dd 23[section. Text]print1:mov eax, [NX]mov EB x, [Ny]mov ecx, Eaxadd eax, ebx; Note the parameter in the stack order: right-to-left push DWORD eax; NX + nypush DWORD ebx; Nypush DWORD Ecx; Nxpush DWORD Strformatcall printfadd ESP, byte 4 * 4ret
#MakeFile nasm-felf32 proc.nas gcc-m32-o main MAIN.C PROC.O
Still using GCC + NASM, can be compiled, but the link to execute the file how all pass, has been error "undefined function"!
Try various operating systems (WinXP 32-bit, Win7 64-bit), a variety of compiler version (MinGW 32-bit, 64-bit), a variety of compilation parameters, engaged in the majority of days, die and die do not let me!
In the fast despair, suddenly remembered the previously browsed C library functions, vaguely remember the function name preceded by an underscore "_"! Is that the reason? Try it ...
extern _printfextern _strformatglobal _print1[section. Data]nx DW 14nY DW 23[section. Text]_print1:mov eax, [NX]mov ebx, [ Ny]mov ecx, eaxadd eax, ebx; Note the parameter in the stack order: right-to-left push DWORD eax; NX + nypush DWORD ebx; Nypush DWORD Ecx; Nxpush DWORD _strformatcall _printfadd ESP, byte 4 * 4ret
Actually, the compilation passed!
Summing up, assembly language (NASM) and C language (GCC) joint compilation ( under the Windows system ), assembly code and C language generated a mixed relationship of variables and functions, preceded by an underscore "_"! The C language code does not add.
GCC and NASM co-compiled