An example ARM assembly language module

Example 7 illustrates some of the core constituents of an assembly language module. The example is written in ARM assembly language.

The constituent parts of this example are:

Example 7 defines a single section called ARMex that contains code and is marked as being READONLY.

Example 7. Constituents of an assembly language module

        AREA     ARMex, CODE, READONLY
                                ; Name this block of code ARMex
        ENTRY                   ; Mark first instruction to execute
        MOV      r0, #10        ; Set up parameters
        MOV      r1, #3
        ADD      r0, r0, r1     ; r0 = r0 + r1
        MOV      r0, #0x18      ; angel_SWIreason_ReportException
        LDR      r1, =0x20026   ; ADP_Stopped_ApplicationExit
        SVC      #0x123456      ; ARM semihosting (formerly SWI)
        END                     ; Mark end of file

Show/hideApplication entry

The ENTRY directive declares an entry point to the program. It marks the first instruction to be executed. In applications using the C library, an entry point is also contained within the C library initialization code. Initialization code and exception handlers also contain entry points.

Show/hideApplication execution

The application code in Example 7 begins executing at the label start, where it loads the decimal values 10 and 3 into registers R0 and R1. These registers are added together and the result placed in R0.

Show/hideApplication termination

After executing the main code, the application terminates by returning control to the debugger. This is done using the ARM semihosting SVC (0x123456 by default), with the following parameters:

  • R0 equal to angel_SWIreason_ReportException (0x18)

  • R1 equal to ADP_Stopped_ApplicationExit (0x20026).

Show/hideProgram end

The END directive instructs the assembler to stop processing this source file. Every assembly language source module must finish with an END directive on a line by itself. Any lines following the END directive are ignored by the assembler.

Show/hideSee also


Developing Software for ARM processors:


Assembler Reference:

Copyright © 2010-2012 ARM. All rights reserved.ARM DUI 0473H