title: How do I sys_write multiple ASCII characters on x64?
body: <p>I am learning assembly and a number of guides explain how to <code>sys_write</code> but only using data stored in <code>.text</code>. I want to print multiple ASCII characters stored on the stack.</p>
  <pre><code>global _start
  
  section .data
  
  section .text
  
  _start:
      push rbp
      mov rbp, rsp
  
      sub rsp, 16
      mov QWORD [rbp], 47
      mov QWORD [rbp - 8], 46
      
      mov rax, 1
      mov rdi, 1
      lea rsi, [rbp]
      mov rdx, 2
      syscall
  
      pop rbp
      
      mov rax, 60
      mov rdi, 0
      syscall
  </code></pre>
  <p>The above code sets up the stack frame (useless for the example), makes room for the local variables and places the ASCII characters for 47 and 46 on the stack. Then it loads the address to the first ASCII character into <code>rsi</code> and calls <code>sys_write</code>. Finally, it calls <code>sys_exit</code>.</p>
  <p>However, when I run the code it only prints: <code>/^@</code>. Running strace produces the following output:</p>
  <pre><code>execve(&quot;./a.out&quot;, [&quot;./a.out&quot;], 0x7ffd1d1c2280 /* 60 vars */) = 0
  write(1, &quot;/\0&quot;, 2/\0)                      = 2
  exit(0)                                 = ?
  +++ exited with 0 +++
  </code></pre>
  <p>I feel like there's a fundamental misunderstanding I have concerning <code>lea</code> or <code>[rbp]</code> but I don't know enough assembly to know what I am missing.</p>