title: Two ways to compile a C program
body: <p>Let's say I have the following C program:</p>
  <pre><code>// hi.c
  int main() {
      int a = 8;
      int b = 13;
      return a + b;
  }
  </code></pre>
  <p>On linux (x86_64 GNU/Linux), here is how I normally compile and run it:</p>
  <pre><code>ubuntu@ip-172-30-1:~/asm$ gcc ./hi.c
  ubuntu@ip-172-30-1:~/asm$ ./a.out
  ubuntu@ip-172-30-1:~/asm$ echo $?
  21
  </code></pre>
  <p>However, I'm having a bit of trouble first compiling it to assembly and then running that. What I am trying now is:</p>
  <pre><code>$ gcc -S hi.c
  $ head -n 5 hi.s
    .file &quot;hi.c&quot;
    .text
    .globl    main
    .type main, @function
   main:
  $ as hi.s -o hi.out
  $ ld hi.out -e main -o hi
  $ ./hi
  Segmentation fault (core dumped)
  </code></pre>
  <p>What am I doing incorrect with assembling/linking/running?</p>