我该怎么办输入/输出与MASM一个控制台上? [英] How can I do Input/Output on a console with MASM?

查看:348
本文介绍了我该怎么办输入/输出与MASM一个控制台上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我GOOGLE和一派,我还没有发现任何有用的东西。我怎么能输出发送到控制台,并从组装控制台接受用户输入的?

I've googled and googled, and I've not found anything useful. How can I send output to the console, and accept user input from the console with assembly?

我使用MASM32

推荐答案

由于filofel说,使用Win32 API。这里有一个小的hello world例如:

As filofel says, use the Win32 API. Here's a small hello world example:

.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 。我将它作为一个练习,你。

Now to capture input, you'd proceed similarly, using API functions such as ReadConsoleInput. I leave that as an exercise to you.

这篇关于我该怎么办输入/输出与MASM一个控制台上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆