I learned MIPS a few years ago in class and have been learning x86_64 recently. A lot of the general knowledge of assembly has transferred over, but the registers and stack are slightly different. I believe understand what and why I need to do, I'm just not sure how to do it.
As far as I'm aware, I need to subtract the stack pointer to open up writable space, write my data to it, and then access it in my function by adding the necessary offset. And from what I've read rbp is the base pointer and rsp is the top pointer. I've been messing around with different offsets though and my code is not printing anything or (in this iteration) segfaulting
section .data
msg db 'Hello, world!', 0xa ; set msg as text with trailing newline
len equ $ - msg ; store length of msg
outfile db 'test_file.txt', 0 ; set outfile as text without trailing newline
msg1 db 'Hell2, world!', 0xa ; set msg1 as text with trailing newline
section .text
global _start ; define symbol for entry point
global exit ; define symbol for exit
global print ; define symbol for print
print:
mov eax, 4 ; set instruction to write
mov ebx, 1 ; set file descriptor to stdout
mov ecx, msg ; set buffer to msg
mov ecx, [rbp+8] ; set buffer to (ideally) msg1
mov edx, len ; set the size to the length of text
int 0x80 ; system call
ret ; return to call location
_start:
sub rbp, len
mov rsp, msg1
call print ; call print function
jmp exit ; jump to program exit code
exit:
mov eax, 1 ; set instruction
mov ebx, 0 ; program exit code
int 0x80 ; system call