- a the basic structure of ARM assembly language source program:
Area Init, CODE, READONLY
ENTRY
Start
LDR R0, =0x3ff5000
LDR R1, 0xFF
STR R1, [R0]
LDR R0, =0x3ff5008
LDR R1, 0x01
STR R1, [R0]
... ... ... ... ... ...
END
In an ARM (THUMB) assembly language Program, the code is organized in program segments.
A segment is a relatively independent instruction or data series that has a specific name. Segments can be divided into code snippets and data segments , the content of the code snippet is the execution code, and the data segment holds the data that is needed to run the code. A assembler should have at least one code snippet, and when the program is longer, it can be split into multiple sections of code and data segments, and multiple segments will eventually form an executable image file when the program compiles the link.
Executable image files are usually composed of the following parts:
-One or more code snippets, the properties of the code snippet are read-only .
-0 or more data segments that contain the initialized data, and the properties of the data segment are read-write .
-0 or more data segments that do not contain initialization data, and the properties of the data segment are read-write .
Depending on the system default or user-defined rules, the linker arranges each segment in the appropriate location in memory. Therefore, the relative position between the middle of the source program and the executable image file in the middle of the relative position is generally not the same.
In an assembly language program, an area pseudo-directive defines a segment and describes the related properties of the defined segment, and this example defines a code snippet named Init, which is read-only. The ENTRY pseudo-directive identifies the entry point of the program , followed by the sequence of instructions, the end of the program is the end pseudo-directive, the pseudo-directive tells the compiler source file ends, each assembler segment must have an end pseudo-directive , indicating the end of the code snippet.
2. A subroutine call to an arm assembly language
Area Init, CODE, READONLY
ENTRY
Start
LDR R0, =0x3ff5000
LDR R1, 0xFF
STR R1, [R0]
LDR R0, =0x3ff5008
LDR R1, 0x01
STR R1, [R0]
BL print_text
... ... ... ... ... ...
Print_text
... ... ... ... ... ...
MOV PC , BL
... ... ... ... ... ...
END
In the ARM assembly language program, the subroutine call is usually implemented by the BL instruction.
In the program, use the instructions:
BL Sub-Program name
to complete the subroutine call
The instruction performs the following operations: The return address of the subroutine is stored in the connection register LR, and the program-meter PC points to the entry point of the subroutine, and when the subroutine is completed, it needs to return to the call, and the return address stored in the LR is re-copied to the program counter PC. When calling a subroutine, you can also complete the pass of the parameter and return the result of the operation from the subroutine, which can usually be done using the Register R0 ~ R3.
The program structure of ARM assembly language