writing to a file in nasm using system calls

2019-09-19 01:11发布

问题:

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.