Windows 7 中 NASM 程序中的 I/O

发布于 2024-08-22 09:12:55 字数 124 浏览 2 评论 0原文

我想用 NASM 汇编语言进行编程。我有 NASM 2.07 和 Borland C++ 编译器 5.0 (bcc32)。我的操作系统是Windows 7。我不知道如何在Windows平台上使用NASM进行输入和输出。请问你能帮我吗?

I want to program in NASM assembly language. I have NASM 2.07 and Borland C++ compiler 5.0 (bcc32). My OS is Windows 7. I do not know how to do input and output with NASM in Windows platform. Please can you help me?

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

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

发布评论

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

评论(2

不语却知心 2024-08-29 09:12:55

最简单的方法是调用 Win32 函数,可以通过链接 kernel32 库 (IIRC) 来访问。

The easiest way is to call the Win32 functions, accessible by linking the kernel32 libs (IIRC).

向地狱狂奔 2024-08-29 09:12:55

您可以使用“C”函数“printf”和“scanf”。
为此,您需要将其声明为“外部”。
有一个简单的例子:

section .data
    input_string   db 0
    format         db "%s", 0
    output_string1 db "type something", 10, 0 ; "type something\n"
    output_string2 db "you wrote: %s", 0

extern _printf
extern _scanf

section .text
global _main
_main:                  ; int main()

    push output_string1 ;
    call _printf        ; printf(string1);
    add  esp, 4         ;

    push output_string1 ;
    push format         ;
    call _scanf         ; scanf(format, string1);
    add  esp, 8         ;


    push input_string   ;
    push output_string2 ;
    call _printf        ; printf(output_string2, input_string);
    add  esp, 8         ;

    xor  eax, eax       ; return 0;
    ret                 ;

You can use the "C" functions "printf" and "scanf".
For doing that you need to declare it as "extern".
There is a simple example:

section .data
    input_string   db 0
    format         db "%s", 0
    output_string1 db "type something", 10, 0 ; "type something\n"
    output_string2 db "you wrote: %s", 0

extern _printf
extern _scanf

section .text
global _main
_main:                  ; int main()

    push output_string1 ;
    call _printf        ; printf(string1);
    add  esp, 4         ;

    push output_string1 ;
    push format         ;
    call _scanf         ; scanf(format, string1);
    add  esp, 8         ;


    push input_string   ;
    push output_string2 ;
    call _printf        ; printf(output_string2, input_string);
    add  esp, 8         ;

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