Last active
February 16, 2019 17:11
-
-
Save TJesionowski/7a5027dbf1359866839fbbb56aee9b94 to your computer and use it in GitHub Desktop.
A simple example of linking assembly programs to C programs.
This file contains hidden or 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
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 |
This file contains hidden or 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
void hello(void); | |
int main(void) | |
{ | |
hello(); | |
return 0; | |
} |
This file contains hidden or 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
#!/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