使用系统调用写入 nasm 中的文件

发布于 2024-10-09 05:46:22 字数 762 浏览 0 评论 0原文

作为作业的一部分,我应该使用系统调用写入文件。一切正常,除了当我尝试在 gedit (Linux) 中打开文件时。它说它无法识别字符编码。记事本(Windows 上)可以正常打开该文件。

为什么这在 Linux 上不起作用?

这是代码:

    section .text

    global _start

        _start:
                    mov EAX, 8
                    mov EBX, filename
                    mov ECX, 0700
                    int 0x80
                    mov EBX, EAX
                    mov EAX, 4
                    mov ECX, text
                    mov EDX, textlen
                    int 0x80
                    mov EAX, 6
                    int 0x80
                    mov eax, 1
                    int 0x80
        
    section .data

        filename db "./output.txt", 0
        text db "hello world", 0
        textlen equ $ - text

As part of an assignment, I'm supposed to write to a file using system calls. Everything works fine except when I try to open the file in gedit (Linux). It says it can't identify the character encoding. Notepad (on Windows) opens the file just fine.

Why doesn't this work on Linux?

Here's the code:

    section .text

    global _start

        _start:
                    mov EAX, 8
                    mov EBX, filename
                    mov ECX, 0700
                    int 0x80
                    mov EBX, EAX
                    mov EAX, 4
                    mov ECX, text
                    mov EDX, textlen
                    int 0x80
                    mov EAX, 6
                    int 0x80
                    mov eax, 1
                    int 0x80
        
    section .data

        filename db "./output.txt", 0
        text db "hello world", 0
        textlen equ $ - text

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

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

发布评论

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

评论(2

晚风撩人 2024-10-16 05:46:22

将第 3 行更改为:
mov ECX,0x0700

change line 3 to this :
mov ECX, 0x0700

情定在深秋 2024-10-16 05:46:22

在输出字符串修复后添加换行符。

Adding a linefeed character after the output string fixed it.

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