title: Assembled program gives error: /a.out: cannot execute binary file: Exec format error
body: <p>I'm new to coding 64-bit x86, but I am running Ubuntu 14.04 (trusty), and I have a very simple 64-bit piece of code that I assemble using <em>as</em>. The output I get has strange permissions and file type.</p>
  
  <p>When I run:</p>
  
  <pre><code>as file.s
  </code></pre>
  
  <p>I get a file <code>a.out</code> with 770 permissions.</p>
  
  <p>I get this error when I execute it:</p>
  
  <blockquote>
    <p>bash: ./a.out: cannot execute binary file: Exec format error</p>
  </blockquote>
  
  <p>When I run:</p>
  
  <pre><code>file ./a.out 
  </code></pre>
  
  <p>I get:</p>
  
  <blockquote>
    <p>./a.out: ELF 64-bit LSB  relocatable, x86-64, version 1 (SYSV), not stripped</p>
  </blockquote>
  
  <p>The assembly code I am using is:</p>
  
  <pre><code>.section    .data
  .LC0:
      .string "/bin/sh"
  
  .LC1:
      .string "/bin/sh"
  
  .LC3:
      .quad .LC1, 0
  
      .text
      .globl  _start
  _start:
  .LFB0:
  
      pushq   %rbp
      movq    %rsp, %rbp
  
      movq    $59,%rax     # System Call to execve
      movq    $.LC0, %rdi  # Pass program to execute
      movq    $.LC3, %rsi  # Pass command line arguments
      syscall
  
      movl    $0, %eax
      popq    %rbp
      ret
  </code></pre>