Skip to content

Instantly share code, notes, and snippets.

@TJesionowski
Last active February 16, 2019 17:11
Show Gist options
  • Save TJesionowski/7a5027dbf1359866839fbbb56aee9b94 to your computer and use it in GitHub Desktop.
Save TJesionowski/7a5027dbf1359866839fbbb56aee9b94 to your computer and use it in GitHub Desktop.
A simple example of linking assembly programs to C programs.
section .data
msg db "Hello, World.asm","\0x0a" ;
section .text
global hello
hello:
mov rax, 1
mov rdi, 1
mov rsi, msg
mov rdx, 17 ; 17 characters in msg
syscall
ret
void hello(void);
int main(void)
{
hello();
return 0;
}
#!/bin/bash
nasm -f elf64 called_hello.asm -o called_hello.o
gcc -c calls_hello.c -o calls_hello.o
ld called_hello.o calls_hello.o
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment