Compiling to Assembly
from Scratch

Table of Contents


Appendix B
GAS v. ARMASM Syntax

Two different syntaxes are used for ARM assembly. The first one is the GNU Assembler (GAS) syntax. It is also supported by the official ARM toolchain based on Clang called armclang.

The other one is the legacy ARMASM syntax. Most likely, you will not need to deal with it, but I include a small Rosetta Stone–style (side-by-side) comparison cheat sheet for completeness.

GNU Assembler Syntax

/* Hello-world program.
   Prints "Hello, assembly!" and exits with code 42. */

.data
  hello:
    .string "Hello, assembly!"

.text
  .global main
  main:
    push {ip, lr}

    ldr r0, =hello
    bl printf

    mov r0, #41
    add r0, r0, #1  // Increment 41 by one.

    pop {ip, lr}
    bx lr

Legacy ARMASM Syntax

; Hello-world program.
; Prints "Hello, assembly!" and exits with code 42.

  AREA ||.data||, DATA
hello
  DCB  "Hello, assembly!",0

  AREA ||.text||, CODE
main PROC
  push {ip, lr}

  ldr r0, =hello
  bl printf

  mov r0, #41
  add r0, r0, #1  ; Increment 41 by one.

  pop {ip, lr}
  bx lr