I am fairly new to ASM. I am calling sys_open and am trying to print the return value of that syscall (I want to see the fd or error). However, my code isn't working. Any help in the right direction is greatly appreciated. Thanks!
Makefile
asm: test.o
ld -o asm test.o
test.o: test.asm
nasm -f elf64 -g test.asm
test.asm
SECTION .text
GLOBAL _start
_start: mov rax, 2 ; sys_open
mov rdi, file ; get file name address
mov rsi, 0 ; read only
syscall
sub al, '0' ; load fd
mov byte [buf], al ; move fd to buf
mov rsi, buf ; set address of buf
mov rdx, 64 ; set length of buf QWORD
call print
.exit: mov rax, 60 ; sys_exit
mov rdi, 0 ; exit success
syscall
; rsi address of buffer
; rdx length of buffer
print: push rax
push rdi
mov rax, 1 ; sys_write
mov rdi, 1 ; stdout
syscall
pop rdi
pop rax
ret
SECTION .data
file DB `test.asm\0`
SECTION .bss
buf RESQ 1
Strace output
execve("./asm", ["./asm"], [/* 26 vars */]) = 0
open("test.asm", O_RDONLY) = 3
write(1, "\323\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 64Ó) = 64
exit(0) = ?
+++ exited with 0 +++