nasm调用C语言printf (windows)

extern _printf ; contains "_"
section .text ; needed
global _main
_main:
push dword [myint] ;myint is address,so [myint] is 1234.
push dword mystring
call _printf
;add esp,byte 8
leave  ;mov esp,ebp / pop ebp 
ret
;segment _DATA ;ok run
section .data ;not needed
myint dd 1234
mystring db 'This number -> %d <- should be 1234',`\n`,0
section .drectve info ;linking info 
		db '/defaultlib:libcmt.lib /subsystem:console'

C:\Users\Administrator\Desktop>nasm -fwin32 demo.asm

C:\Users\Administrator\Desktop>link demo.obj
Microsoft (R) Incremental Linker Version 12.00.21005.1
Copyright (C) Microsoft Corporation.  All rights reserved.


C:\Users\Administrator\Desktop>demo
This number -> 1234 <- should be 1234

你可能感兴趣的:(C/C++,Assembler,Windows)