writing to a file in nasm using system calls

时光毁灭记忆、已成空白 提交于 2020-01-06 08:36:09

问题


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 it 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

thanks :)

-- update: added a linefeed character after the output string and it fixed it.


回答1:


change line 3 to this : mov ECX, 0x0700




回答2:


fixed it, see update in the question.



来源:https://stackoverflow.com/questions/4526424/writing-to-a-file-in-nasm-using-system-calls

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!