I'm a new to x86 and currently writing a program where I need to write a file after doing some operations with data I read from a file, but I am facing problems when I write the result to a file, because it is writing with some weird enconding.
Here I reserve the space I am going to need to store the result and the output file:
section .data
new_file db "new_file.txt", 0
section .bss
data resb 4
The code that writes data to a file called new_file.txt:
mov rax, SYS_OPEN
mov rdi, new_file
mov rsi, O_CREAT + O_WRONLY
mov rdx, 0644o
syscall
push rax
mov rdi, rax
mov rax, SYS_WRITE
mov rsi, data
mov rdx, 4
syscall
mov rax, SYS_CLOSE
pop rdi
syscall
For example, assume that I want to do some addition and then store the result in data to write it later:
mov rax, 0xF
add rax, 0x1
mov [data], rax
in this case the data would have a value of 0x10 and when I check the file generated I get something like this:
I'm lost since I don't seem to find anything about encoding in x86, so any help would be appreciated.