aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/arch/x86_64.md
diff options
context:
space:
mode:
Diffstat (limited to 'src/arch/x86_64.md')
-rw-r--r--src/arch/x86_64.md39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/arch/x86_64.md b/src/arch/x86_64.md
index d55ccd6..964bf00 100644
--- a/src/arch/x86_64.md
+++ b/src/arch/x86_64.md
@@ -148,6 +148,44 @@ must must save these registers in case they are used.
LO ADDR
```
+## ASM skeleton
+Small assembler skeleton, ready to use with following properties:
+- use raw Linux syscalls (`man 2 syscall` for ABI)
+- no `C runtime (crt)`
+- gnu assembler [`gas`][gas_doc]
+- intel syntax
+```x86asm
+# file: greet.s
+
+ .intel_syntax noprefix
+
+ .section .text, "ax", @progbits
+ .global _start
+_start:
+ mov rdi, 1 # fd
+ lea rsi, [rip + greeting] # buf
+ mov rdx, [rip + greeting_len] # count
+ mov rax, 1 # write(2) syscall nr
+ syscall
+
+ mov rdi, 0 # exit code
+ mov rax, 1 # exit(2) syscall nr
+ syscall
+
+ .section .rdonly, "a", @progbits
+greeting:
+ .asciz "Hi ASM-World!\n"
+greeting_len:
+ .int .-greeting
+```
+> Syscall numbers are defined in `/usr/include/asm/unistd.h`.
+
+To compile and run:
+```bash
+> gcc -o greet greet.s -nostartfiles -nostdlib && ./greet
+Hi ASM-World!
+```
+
## References
- [SystemV AMD64 ABI][sysvabi]
- [AMD64 Vol1: Application Programming][amd64_vol1]
@@ -167,4 +205,5 @@ must must save these registers in case they are used.
[intel64_vol1]: https://software.intel.com/content/www/us/en/develop/download/intel-64-and-ia-32-architectures-software-developers-manual-volume-1-basic-architecture.html
[intel64_vol2]: https://software.intel.com/content/www/us/en/develop/download/intel-64-and-ia-32-architectures-sdm-combined-volumes-2a-2b-2c-and-2d-instruction-set-reference-a-z.html
[intel64_vol3]: https://software.intel.com/content/www/us/en/develop/download/intel-64-and-ia-32-architectures-sdm-combined-volumes-3a-3b-3c-and-3d-system-programming-guide.html
+[gas_doc]: https://sourceware.org/binutils/docs/as
[gas_directives]: https://sourceware.org/binutils/docs/as/Pseudo-Ops.html#Pseudo-Ops