commit 9973b9a6e90e08712abca8fcac25b4f612975fd9 Author: Antoine Date: Mon Jul 13 12:27:16 2020 +0200 add sample hello world assembly exec diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e697aaa --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +hello +*.obj diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..dfcb3ea --- /dev/null +++ b/Makefile @@ -0,0 +1,15 @@ +.PHONY: compile link info exec + +dyn: compile link exec + +compile: + as hello.s -o hello.obj +link: + @#ld -m elf_x86_64 --entry=main -lc --dynamic-linker /lib64/ld-linux-x86-64.so.2 -o hello hello.obj + ld -m elf_x86_64 -o hello hello.obj + +exec: + @./hello + +info: + readelf -a hello diff --git a/hello.s b/hello.s new file mode 100644 index 0000000..50aa28a --- /dev/null +++ b/hello.s @@ -0,0 +1,22 @@ +.text # section declaration + # we must export the entry point to the ELF linker or +.global _start # loader. They conventionally recognize _start as their + # entry point. Use ld -e foo to override the default. +_start: + # write our string to stdout + + movl $len,%edx # third argument: message length + movl $msg,%ecx # second argument: pointer to message to write + movl $1,%ebx # first argument: file handle (stdout) + movl $4,%eax # system call number (sys_write) + int $0x80 # call kernel + # and exit + + movl $0,%ebx # first argument: exit code + movl $1,%eax # system call number (sys_exit) + int $0x80 # call kernel + +.data # section declaration + msg: + .ascii "Hello, world!\n" # our dear string + len = . - msg # length of our dear string