正如 filofel 所说,使用 Win32 API。这是一个简单的 hello world 示例:
.386
.MODEL flat, stdcall
STD_OUTPUT_HANDLE EQU -11
GetStdHandle PROTO, nStdHandle: DWORD
WriteConsoleA PROTO, handle: DWORD, lpBuffer:PTR BYTE, nNumberOfBytesToWrite:DWORD, lpNumberOfBytesWritten:PTR DWORD, lpReserved:DWORD
ExitProcess PROTO, dwExitCode: DWORD
.data
consoleOutHandle dd ?
bytesWritten dd ?
message db "Hello World",13,10
lmessage dd 13
.code
main PROC
INVOKE GetStdHandle, STD_OUTPUT_HANDLE
mov consoleOutHandle, eax
mov edx,offset message
pushad
mov eax, lmessage
INVOKE WriteConsoleA, consoleOutHandle, edx, eax, offset bytesWritten, 0
popad
INVOKE ExitProcess,0
main ENDP
END main
组装:
ml.exe helloworld.asm /link /subsystem:console /defaultlib:kernel32.lib /entry:main
现在要捕获输入,您可以使用 API 函数进行类似的操作,例如ReadConsoleInput
。我把它留给你作为练习。