diff options
author | johannst <johannst@users.noreply.github.com> | 2020-09-19 13:57:06 +0000 |
---|---|---|
committer | johannst <johannst@users.noreply.github.com> | 2020-09-19 13:57:06 +0000 |
commit | 28f631e02bbf7e4cbd763fc74c4941d3f55a030f (patch) | |
tree | a3633cec0067d5b2e2e97737855b62de90c054b0 /arch | |
parent | eaaab502c1a10032f4533ca013a39f1a83a7f82b (diff) | |
download | notes-28f631e02bbf7e4cbd763fc74c4941d3f55a030f.tar.gz notes-28f631e02bbf7e4cbd763fc74c4941d3f55a030f.zip |
deploy: 4a5cd61b7c536ecf1bdb288cb6d584c190b1f6c7
Diffstat (limited to 'arch')
-rw-r--r-- | arch/x86_64.html | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/arch/x86_64.html b/arch/x86_64.html index 492927f..26679a1 100644 --- a/arch/x86_64.html +++ b/arch/x86_64.html @@ -287,6 +287,44 @@ LO ADDR </code></pre> </li> </ul> +<h2><a class="header" href="#asm-skeleton" id="asm-skeleton">ASM skeleton</a></h2> +<p>Small assembler skeleton, ready to use with following properties:</p> +<ul> +<li>use raw Linux syscalls (<code>man 2 syscall</code> for ABI)</li> +<li>no <code>C runtime (crt)</code></li> +<li>gnu assembler <a href="https://sourceware.org/binutils/docs/as"><code>gas</code></a></li> +<li>intel syntax</li> +</ul> +<pre><code class="language-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 +</code></pre> +<blockquote> +<p>Syscall numbers are defined in <code>/usr/include/asm/unistd.h</code>.</p> +</blockquote> +<p>To compile and run:</p> +<pre><code class="language-bash">> gcc -o greet greet.s -nostartfiles -nostdlib && ./greet +Hi ASM-World! +</code></pre> <h2><a class="header" href="#references" id="references">References</a></h2> <ul> <li><a href="https://www.uclibc.org/docs/psABI-x86_64.pdf">SystemV AMD64 ABI</a></li> |