diff options
author | johannst <johannes.stoelp@gmail.com> | 2020-09-19 13:14:59 +0200 |
---|---|---|
committer | johannst <johannes.stoelp@gmail.com> | 2020-09-19 13:14:59 +0200 |
commit | 2c894f0c6803cf893fe1c8b10e835831499bb10b (patch) | |
tree | b4bc3893768c74f31277df6dcbce66116f8bb5e7 /src | |
parent | 09fbd7db16e7e3f67f5f3a456cd1c7c2583b821e (diff) | |
download | notes-2c894f0c6803cf893fe1c8b10e835831499bb10b.tar.gz notes-2c894f0c6803cf893fe1c8b10e835831499bb10b.zip |
x86_64 added asm snippt (Linux)
Diffstat (limited to 'src')
-rw-r--r-- | src/arch/x86_64.md | 39 |
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 |