.386
.model flat, stdcall
GetStdHandle PROTO, ; get standard handle
nStdHandle:DWORD ; type of console handle
WriteConsoleA PROTO, ; write a buffer to the console
hConsoleOutput:DWORD, ; output handle
lpBuffer:PTR BYTE, ; pointer to buffer
nNumberOfCharsToWrite:DWORD, ; size of buffer
lpNumberOfCharsWritten:PTR DWORD, ; ptr to number of bytes written
lpReserved:DWORD ; (not used)
ExitProcess PROTO, ; exit program
dwExitCode:DWORD ; return code
.data
prompt BYTE "HELLO WORLD",0
consoleOutHandle DWORD ? ; handle to standard output device
bytesWritten DWORD ?
STD_OUTPUT_HANDLE EQU -11
.code
main PROC
INVOKE GetStdHandle, STD_OUTPUT_HANDLE
mov [consoleOutHandle],eax
mov edx, OFFSET prompt
mov eax, 11
INVOKE WriteConsoleA,
consoleOutHandle, ; console output handle
edx, ; points to string
eax, ; string length
OFFSET bytesWritten, ; returns number of bytes written
0
INVOKE ExitProcess,0
main ENDP
END main
将以上代码保存为helloworld.asm
运行要求:
下载Visual Studio,安装C++
安装好以后,打开该命令行
在命令行中输入以下命令:
分别是编译,链接,运行,即可
ml /c /coff helloworld.asm
link /subsystem:console kernel32.lib user32.lib helloworld.obj
helloworld.exe