sys_open wants the address (offset) of a zero-terminated string containing the filename in ebx.
; nasm -f elf32 myfile.asm
; ld -o myfile myfile.o
global _start ; tell ld about our entrypoint
section .data
filename db "receipt.txt", 0
section .bss
file_descriptor resd 1
section .text
_start:
mov eax, 5 ;__NR_open
mov ebx, filename
mov ecx, 2 ; open mode (is 2 right for what you want?)
mov edx, 700 ; file permissions (if we're creating it) - usually octal!
int 80h
cmp eax, -4096
ja error
mov [file_descriptor], eax
;... read, write, whatever
; close file
mov eax, 6 ; __NR_close
mov ebx, [file_descriptor]
int 80h
error:
mov ebx, eax
neg ebx ; make it positive - can read this with "echo $?"
; don't forget to exit cleanly!
exit:
mov eax, 1 ; __NR_exit
int 80h
Something like that... This assumes that the file is in the current directory - sys_open doesn't know about the "PATH" environment variable, so you may need to specify the full path in the "filename" string, if it's elsewhere. That's untested code, but I think it's fairly near right (famous last words!). Try something like that, and if it doesn't work, do "echo $?" to find out the error number. Then look it up, and see what went wrong. If you can't fix it, get back to us.
(Incidentally - put "code" in square brackets - like a Nasm memory reference - at the beginning of your code, and "/code" in square brackets at the end of your code, lest the forum software get confused)
Best,
Frank