简体   繁体   English

如何在fasm中写入控制台?

[英]How to write to the console in fasm?

I'm exceptionally new to assembly. 我对组装非常新。 I only picked it up yesterday and I've looked through many examples and still can't figure out for myself how to write to the console. 我昨天才拿起它,我看了很多例子,但仍然无法弄清楚如何写入控制台。 I always get an error when I seem to replicate it in my own way. 当我似乎以自己的方式复制它时,我总是会遇到错误。

The easiest way is to use the C functions. 最简单的方法是使用C函数。 In its simplest use, printf() takes a string as a parameter and writes it on the standard output. 在最简单的用法中, printf()接受一个字符串作为参数并将其写入标准输出。

This code should work: 这段代码应该有效:

format PE console
entry start

include 'win32a.inc'

section '.text' code executable
start:
        push hello
        call [printf]
        pop ecx

        push 0
        call [ExitProcess]

section '.rdata' data readable
        hello db 'Hello world!', 10, 0

section '.idata' data readable import
        library kernel32, 'kernel32.dll', \
                msvcrt,   'msvcrt.dll'
        import kernel32, ExitProcess, 'ExitProcess'
        import msvcrt, printf, 'printf'

Use WriteConsole . 使用WriteConsole

include 'win32wxp.inc'

.code
  start:
        invoke  AllocConsole
        invoke  WriteConsole,<invoke GetStdHandle,STD_OUTPUT_HANDLE>,tex,12,dummy,0
        invoke  Sleep,-1
.end start

.data
tex     TCHAR   'Hello World!'
dummy   rd      1  

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM