title: GCC: How to assemble a file in one command?
body: <p>It's easy to compile C source code into an executable: <code>gcc hello.c -o hello</code>. In contrast, this is how I am currently turning an assembly program into an executable:</p>
  
  <pre><code>cpp -P hello.S &gt; hello.s  # Run preprocessor.
  as hello.s -o hello.o  # Assemble.
  ld hello.o -o hello  # Link.
  </code></pre>
  
  <p>Is there a way to do all of this using one command?</p>
  
  <p>The OS is Debian 10.1 Buster running on a mipsel (32-bit MIPS little endian) machine.</p>
  
  <p>For reference, this is <code>hello.S</code>, a MIPS assembly program that requires the use of the C preprocessor:</p>
  
  <pre><code>#include &lt;regdef.h&gt;
  #include &lt;sys/syscall.h&gt;
  
  .data
      mymsg: .asciiz "Hello\n"
  
  .text
      .global __start
  
  __start:
      li a0, 1
      la a1, mymsg
      li a2, 6
      li v0, SYS_write
      syscall
      li a0, 1
      li v0, SYS_exit
      syscall
  </code></pre>