5.3.2. An example ARM assembly language module

Example 5.1 illustrates some of the core constituents of an assembly language module. The example is written in ARM assembly language. It is supplied as armex.s in the examples\asm subdirectory of the toolkit. Refer to Code examples for instructions on how to assemble, link, and execute the example.

The constituent parts of this example are described in more detail in the following sections.

Example 5.1. 

								; Name this block of code ARMex.
		ENTRY						; Mark first instruction to execute
start		MOV		r0, #10				; Set up parameters
		MOV 		r1, #3
		ADD		r0, r0, r1				; r0 = r0 + r1
stop		MOV		r0, #0x18				; angel_SWIreason_ReportException
		LDR		r1, =0x20026				; ADP_Stopped_ApplicationExit
		SWI 		0x123456				; Angel semihosting ARM SWI
		END						; Mark end of file

The AREA directive

ARM Object Format (AOF) areas are independent, named, indivisible sequences of code or data. A single code area is the minimum required to produce an application.

The output of an assembly or compilation usually consists of two or more areas:

  • A code area. This is usually a read-only area.

  • A data area. This is usually a read-write area.

The linker places each area in a program image according to area placement rules. Areas that are adjacent in source files are not necessarily adjacent in the application image. Refer to Chapter 6 Linker in the ARM Software Development Toolkit Reference Guide for more information on how the linker places areas. See also Chapter 10 Writing Code for ROM.

In an ARM assembly language source file, the start of an area is marked by the AREA directive. This directive names the area and sets its attributes. The attributes are placed after the name, separated by commas. Refer to Chapter 5 Assembler in the ARM Software Development Toolkit Reference Guide for a detailed description of the syntax of the AREA directive.

You can choose any name for your areas. However, names starting with any nonalphabetic character must be enclosed in bars, or a missing AREA name error is generated. For example: |1_DataArea|.

Certain names are conventional. For example, |C$$code| is used for code areas produced by the C compiler, or for code areas otherwise associated with the C library.

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

The ENTRY directive

The ENTRY directive marks the first instruction to be executed within an application. Because an application cannot have more than one entry point, the ENTRY directive can appear in only one of the source modules. In applications containing C code, the entry point is often contained within the C library initialization code.

Application execution

The application code in Example 5.1 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 termination

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

  • r0 equal to angel_SWIreason_ReportException (by default 0x18)

  • r1 equal to ADP_Stopped_ApplicationExit (by default 0x20026)

For additional information on this, see Chapter 13 Angel.

The END directive

This 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.

Copyright © 1997, 1998 ARM Limited. All rights reserved.ARM DUI 0040D