Skip to content

Instantly share code, notes, and snippets.

@jmitchell
Last active September 11, 2017 05:09
Show Gist options
  • Save jmitchell/9c9791a5fcd5204fb48d6eaa81f60c37 to your computer and use it in GitHub Desktop.
Save jmitchell/9c9791a5fcd5204fb48d6eaa81f60c37 to your computer and use it in GitHub Desktop.
Call C from x86-64 assembly
#include <stdio.h>
void hello(void) {
printf("Hello, World!\n");
return;
}
global main
extern hello
section .text
main:
call hello
;call hello
; exit(0)
mov rax, 60
xor rdi, rdi
syscall
main: main.o hello.o
gcc -o main main.o hello.o
main.o: main.asm
nasm -felf64 -o main.o main.asm
hello.o: hello.c
gcc -c -o hello.o hello.c
.PHONY: clean
clean:
rm -f *.o main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment