4.1 Assembling ARM and GNU syntax assembly code

The ARM® Compiler 6 toolchain can assemble both ARM and GNU syntax assembly language source code.

ARM and GNU are two different syntaxes for assembly language source code. They are similar, but have a number of differences. For example, ARM syntax identifies labels by their position at the start of a line, while GNU syntax identifies them by the presence of a colon.

Note:

The GNU Binutils - Using as documentation provides complete information about GNU syntax assembly code.

The Migration and Compatibility Guide contains detailed information about the differences between ARM and GNU syntax assembly to help you migrate legacy assembly code.

The following examples show equivalent ARM and GNU syntax assembly code for incrementing a register in a loop.

ARM syntax assembly:

; Simple ARM syntax example
;
; Iterate round a loop 10 times, adding 1 to a register each time.

        AREA ||.text||, CODE, READONLY, ALIGN=2

main PROC
        MOV      w5,#0x64      ; W5 = 100
        MOV      w4,#0         ; W4 = 0
        B        test_loop     ; branch to test_loop
loop
        ADD      w5,w5,#1      ; Add 1 to W5
        ADD      w4,w4,#1      ; Add 1 to W4
test_loop
        CMP      w4,#0xa       ; if W4 < 10, branch back to loop
        BLT      loop
        ENDP

        END

You might have legacy assembly source files that use the ARM syntax. Use armasm to assemble legacy ARM syntax assembly code. Typically, you invoke the armasm assembler as follows:

armasm --cpu=8-A.64 -o file.o file.s

GNU syntax assembly:

// Simple GNU syntax example                          
// 
// Iterate round a loop 10 times, adding 1 to a register each time.

        .section .text,"ax"                          
        .balign 4                               

main:                                        
        MOV      w5,#0x64      // W5 = 100                  
        MOV      w4,#0         // W4 = 0
        B        test_loop     // branch to test_loop 
loop:
        ADD      w5,w5,#1      // Add 1 to W5
        ADD      w4,w4,#1      // Add 1 to W4
test_loop:
        CMP      w4,#0xa       // if W4 < 10, branch back to loop
        BLT      loop
        .end                                    

Use GNU syntax for newly created assembly files. Use the armclang assembler to assemble GNU assembly language source code. Typically, you invoke the armclang assembler as follows:

armclang --target=aarch64-arm-none-eabi -c -o file.o file.s
Non-ConfidentialPDF file icon PDF versionARM 100066_0608_00_en
Copyright © 2014–2017 ARM Limited or its affiliates. All rights reserved.