reading file's content and printing it to stdout in assembly x64

1.6k views Asked by At

I wrote a very simple assembly program (x64, linux) which reads the contents from /etc/passwd (doesn't really matter from where) and writes it to stdout. I compile it with nasm (nasm -f elf64 foo.asm -o bar). I receive the following error: ./bar: 24: Syntax error: EOF in backquote substitution

Here is my code:

global _start
section .data
    fn:  db  '/etc/passwd',0

section .bss

section .text
_start:
    ; open the file
    xor rax,rax
    add al, 2
    lea rdi, [fn]
    xor rsi, rsi
    syscall

    ; read the file, use some area
    ; in the stack to store the contents
    mov rdi, rax
    sub sp, 0xfff
    lea rsi, [rsp]
    xor rdx, rdx
    mov dx, 0x200
    xor rax, rax
    syscall

    ; write to stdout
    xor rdi, rdi
    add dil, 1
    mov rdx, rax
    xor rax, rax
    add al,1 
    syscall
    ; exit
    xor rax,rax
    add al, 60
    syscall

Is is also possible to get more info about the error? the program compiles with no errors in nasm. Thanks :)!

0

There are 0 answers