You copied the Doc URL to your clipboard.

An example A32 assembly language module

An A32 assembly language module has several constituent parts.

These are:

  • ELF sections (defined by the AREA directive).

  • Application entry (defined by the ENTRY directive).

  • Application execution.

  • Application termination.

  • Program end (defined by the END directive).

Constituents of an A32 assembly language module

The following example defines a single section called A32ex that contains code and is marked as being READONLY. This example uses the A32 instruction set.

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

Constituents of an A64 assembly language module

The following example defines a single section called A64ex that contains code and is marked as being READONLY. This example uses the A64 instruction set.

        AREA     A64ex, CODE, READONLY                                ; Name this block of code A64ex        ENTRY                   ; Mark first instruction to executestart        MOV      w0, #10        ; Set up parameters        MOV      w1, #3        ADD      w0, w0, w1     ; w0 = w0 + w1stop        MOV      x1, #0x26        MOVK     x1, #2, LSL #16        STR      x1, [sp,#0]    ; ADP_Stopped_ApplicationExit        MOV      x0, #0        STR      x0, [sp,#8]    ; Exit status code        MOV      x1, sp         ; x1 contains the address of parameter block        MOV      w0, #0x18      ; angel_SWIreason_ReportException        HLT      0xf000         ; AArch64 semihosting        END                     ; Mark end of file

Application entry

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

Application execution

The application code 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.

Application execution

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

Application termination

After executing the main code, the application terminates by returning control to the debugger. You do this in A32 using the A32 semihosting SVC (0x123456 by default), or in A64, using HLT 0xF000 to invoke the semihosting interface.

A32 code uses the following parameters:

  • R0 equal to angel_SWIreason_ReportException (0x18).

  • R1 equal to ADP_Stopped_ApplicationExit (0x20026).

A64 code uses the following parameters:

  • W0 equal to angel_SWIreason_ReportException (0x18).

  • X1 is the address of a block of two parameters. The first is the exception type, ADP_Stopped_ApplicationExit (0x20026) and the second is the exit status code.

Program end

The END directive instructs the assemblerto stop processing this source file. Every assembly language sourcemodule must finish with an END directiveon a line by itself. Any lines following the END directiveare ignored by the assembler.

Related reference

Was this page helpful? Yes No