Last active
September 11, 2017 05:09
-
-
Save jmitchell/9c9791a5fcd5204fb48d6eaa81f60c37 to your computer and use it in GitHub Desktop.
Call C from x86-64 assembly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
void hello(void) { | |
printf("Hello, World!\n"); | |
return; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
global main | |
extern hello | |
section .text | |
main: | |
call hello | |
;call hello | |
; exit(0) | |
mov rax, 60 | |
xor rdi, rdi | |
syscall |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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