| |||
| Home > Writing ARM Assembly Language > Structure of assembly language modules > An example ARM assembly language module | |||
Example 2.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 main examples directory .
See Code examples for instructions
on how to assemble, link, and execute the example.install_directory\RVDS\Examples
The constituent parts of this example are described in more detail in the following sections.
Example 2.1.
AREA ARMex, CODE, READONLY
; 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
SVC #0x123456 ; ARM semihosting (formerly SWI)
END ; Mark end of file
ELF sections are independent, named, indivisible sequences of code or data. A single code section is the minimum required to produce an application.
The output of an assembly or compilation can include:
one or more code sections. These are usually read-only sections.
one or more data sections. These are usually read-write sections. They might be zero initialized (ZI).
The linker places each section in a program image according to section placement rules. Sections that are adjacent in source files are not necessarily adjacent in the application image. See Chapter 5 Using Scatter-loading Description Files in the Linker User Guide for more information on how the linker places sections.
In a source file, the AREA directive marks the
start of a section. This directive names the section and sets its
attributes. The attributes are placed after the name, separated
by commas. See AREA for
a detailed description of the syntax of the AREA directive.
You can choose any name for your sections. However, names
starting with any nonalphabetic character must be enclosed in bars,
or an AREA name missing error is generated. For
example, |1_DataArea|.
Example 2.1 defines
a single section called ARMex that contains code
and is marked as being READONLY.
The ENTRY directive marks the first instruction
to be executed. In applications containing C code, an entry point
is also contained within the C library initialization code. Initialization
code and exception handlers also contain entry points.
The application code in Example 2.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.
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).
See Chapter 8 Semihosting in the RVCT Developer Guide.