Detritus wrote: ↑Sat Jun 20, 2020 2:14 pm
My goodness. He's already teaching Tal a thing or two!
I wish I was good enough to teach.
So, I have found my problem, and it's the dumbest thing. In-order to write and read from a file in assembly, you have to reopen it after you do one or the other, making the 0_RDWR flag completely worthless. Why would I ever use a flag that allows me to do two things at once, when I can't do two things at once?
Here's the code, for anyone who's interested, to amuse themselves with.
section .data
p db 'helloworld.txt', 0
msg db 'hello world'
len equ $ - msg
section .bss
msg1: resb 64
section .text
global _start
_start:
mov rax, 2 ;open file
mov rdi, p ;file descriptor
mov rsi, 2 ;0_RDWR flag
syscall
mov rdi, rax ;move the file descriptor into RDI, because you can't do that manually for some reason
mov rax, 1 ;sys_write
mov rsi, msg ;content
mov rdx, len ;content length
syscall
mov rax, 2 ;open file again
mov rdi, p ;file descriptor
mov rsi, 2 ;0_RDWR flag
syscall
mov rdi, rax ;And we'll do it again
mov rax, 0 ;sys_read
mov rsi, msg1 ;variable to place content into
mov rdx, 11 ;length to read
syscall
mov rax, 3 ;close file, something that seems pointless because it doesn't work
mov rdi, p ;file descriptor
syscall
mov rax, 1 ;sys_write
mov rdi, 1 ;set to output
mov rsi, msg1 ;content
mov rdx, 64 ;content's potential length
syscall
mov rax, 60 ;die
syscall