Skip to content

Instantly share code, notes, and snippets.

@bmcculley
Created September 7, 2018 04:59
Show Gist options
  • Save bmcculley/ad41cb557f7325a2a4c4c3e8122ab6d6 to your computer and use it in GitHub Desktop.
Save bmcculley/ad41cb557f7325a2a4c4c3e8122ab6d6 to your computer and use it in GitHub Desktop.
Calling a c function from assembly example.
int hello() {
return 123;
}
extern hello
extern printf
extern exit
global _start
section .data
fmt: db "%d", 10, 0
section .text
_start:
call hello ; hello()
mov rsi,rax
mov rdi,fmt
call printf ; printf(format, rsi)
push 0
call exit ; exit(0)
all:
gcc -Wall -c hello.c
nasm -f elf64 main.asm
ld main.o hello.o -lc -I /lib64/ld-linux-x86-64.so.2
clean:
rm a.out hello.o main.o
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment