I'm currently learning Assembly.
I wrote a function to print strings:
global sys_print
sys_print:
; store the stack pointer
push rbp
mov rbp, rsp
; get the string to print
mov rdi, [rbp + 0x18]
; get length of the string
mov rsi, [rbp + 0x10]
; print the string
mov rax, 0x2000004
mov rdx, rsi
syscall
; restore the stack pointer
pop rbp
ret
And then used this function in a second script:
extern sys_print
global _main
section .data
hello db 'Hello, world!', 0x0a, 0
len equ $ - hello
section .text
align 16
_main:
lea rdi, [rel hello]
mov rsi, len
push rdi
push rsi
call sys_print
add rsp, 16
mov eax, 0x2000001
xor edi, edi
syscall
I tryied many diffrent things but when I compile and run the assembly just nothing happens.
$ ./hello
$
I compile the file with the defintion of the print function using:
$ nasm -f macho64 sys_print.asm -o libraryObjects/sys_print.o
And the main.asm file I compile using:
$ nasm -f macho64 -o main.o main.asm
$ gcc -o hello main.o sys_print.o
I don't understand why it doesn't work. The print_sys function must be in a diffrent file goal is to link it in.
Thanks for you help!
OS: macos ventura CPU: intel dual chip