I have the following assembly code
global main
extern println
section .text
main:
mov rdi, message
call println
ret
message:
db "Hello, world!", 0
I am linking it with some C code
#include <stdio.h>
void println(char *line) {
puts(line);
}
I run the following commands to compile and link these two programs
nasm -f elf64 helloWorld.asm -o helloWorld.asm.o
gcc -c helloWorld.c -o helloWorld.c.o
gcc -static helloWorld.c.o helloWorld.asm.o -o helloWorld
then I run my finished program with
./helloWorld
If I remove -static
from the gcc
options, I get a seg-fault! Why is this??