如何在fasm中写入控制台?

发布于 2024-08-27 04:39:28 字数 77 浏览 4 评论 0原文

我对装配非常陌生。我昨天才拿起它,我已经浏览了很多示例,但仍然无法自己弄清楚如何写入控制台。当我似乎以自己的方式复制它时,我总是会遇到错误。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

谁的新欢旧爱 2024-09-03 04:39:29

最简单的方法是使用 C 函数。在最简单的用法中,printf() 将字符串作为参数并将其写入标准输出。

这段代码应该可以工作:

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'

The easiest way is to use the C functions. In its simplest use, printf() takes a string as a parameter and writes it on the standard output.

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'
飞烟轻若梦 2024-09-03 04:39:29

使用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  

Use 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  
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文