I'm trying to call a function from a .s file in a .c file, compiled with gcc, in the following way:
print.s
.section .data
str1: .string "Print anything\n"
.section .text
.globl print
print:
movq $0, %rax
movq $str1, %rdi
call printf
main.c
int main(void){
print();
return 0;
}
and compilling/ running like this:
run.sh
as print.s -o print.o
gcc -g -c main.c -o main.o
gcc -static main.o print.o -o print
./print
For some reason, the program prints the string "Print anything\n", then quickly segfaults. Why is this happening?