i am building and running a code in NASM on a x86_64 Linux.
The program calls the GNU libc printf
function from my program.
The program only must print a sentence to stdout.
; comment
section .data
fmt: db "Hello %s %c", 0
name: db "Jane Doe", 0
section .text
global _start
extern printf
func:
lea rdi, [fmt]
lea rsi, [name]
mov rcx, 0x0A
xor rax, rax
call printf
ret
_start:
call func
; exit
mov rax, 1
mov rbx, 0
int 80h
ret
Here is the way i compile it :
nasm -f elf64 Program.s -o Program.o -Werror
ld -m elf_x86_64 Program.o -o Program -lc -dynamic-linker /lib64/ld-linux-x86-64.so.2
When i run the program, it outputs to the terminal Hello Jane Doe
. Ok, that is what i am expecting.
But when i redirect the out as following :
./Program > output.txt
The file output.txt
is empty.
-rw-rw-r-- 1 me me 0 output.txt
Any idea ? It seems that the libc printf
is in this case printing into another file descriptor than stdout
but maybe i am wrong.
SOLUTION
The solution has been found by a user in the comments.
Switching
; exit
mov rax, 1
mov rbx, 0
int 80h
by call exit
did the trick.