Table of contents
Reference book: "ARM Architecture and Programming (2nd Edition)"
ARM instruction classification and addressing
Introduction to ARM instruction set
ARM assembly language programming
pseudo operation
ARM
In the assembly language source program, statements are composed of instructions, pseudo operations and macro instructions, which are mainly divided into: symbol definition, data definition, assembly control, data frame description, information report and other pseudo operations
Symbol definition
The symbol definition pseudo-operation is used to define ARM
variables in the assembler, assign values to variables, and register names.
GBLA、GBLL及GBLS
: Declare global variablesLCLA、LCLL及LCLS
: Declare local variablesSETA、SETL及SETS
: Assign a value to a variableRLIST
: Define the name for the general register listCN
: Define names for coprocessor registersCP
: Define a name for the coprocessorDN 及SN
: Define names for VFP registersFN
: Define names for FPA’s floating point registers
GBLA、GBLL及GBLS
GBLA
: Declare a global arithmetic variable and initialize it to0
.GBLL
: Declare a global logical variable and initialize it to{FALSE}
.GBLS
: Declare a global string variable and initialize it to an empty string""
.
Syntax format:<gblx> variable
GBLA objectsize ; 声明一个全局的算术变量
GBLL statusB ; 声明一个全局的逻辑变量statusB,默认为{
Flase}
statusB SETL {
TRUE} ; 设置为TRUE
LCLA、LCLL及LCLS
LCLA
: Determine a local arithmetic variable and initialize it to0
.LCLL
: Declare a local logical variable and initialize it to{FALSE}
.LCLS
: Declare a local string variable and initialize it to an empty string""
.
Syntax format:<lclx> variable
# 同全局变量
SETA、SETL及SETS
:
SETA
: Assign a value to an arithmetic variable.SETL
: Assign a value to a logical variable.SETS
: Assign a value to a string variable.
Syntax format:<setx> variable expr
LCLA tmp
tmp SETA 2 ; 给tmp变量赋值为2
RLIST
: Define a name for a general register list.
Syntax format:name RLIST {list-of-registers}
In the LDM/STM instruction, the access order of the registers in the register list is always to access the lower-numbered register first, and then to the higher-numbered register, regardless of the order in which the registers are arranged in the register list.
context RLIST {
r0-r6,r8,r10-r12,r15}
CN
: Defines a name for a coprocessor register.
Syntax format:name CN expr
expr
is the number of the coprocessor, the value range is 0-15
power CN 6
CP
: Define a name for a coprocessor.
# 同上
DN 及SN
DN
: Define a name for a double-precision VFP register.SN
: Define a name for a single-precision VFP register.
Syntax format:name DN/SN expr
expr is the VFP double-precision register number (0-15) or VFP single-precision register number (0-31)
FN
: Define a name for an FPA floating point register.
Syntax format:name FN expr
expr is the number of the floating-point register, and the value range is 0-7.
data definition
Data Definition pseudo-operations include the following specific pseudo-operations.
LTORG
: Declares the beginning of a data buffer pool (Literal Pool).MAP
: Define the first address of a structured memory table (Storage Map).FIELD
: Define a data field (Field) in a structured memory table.SPACE
: Allocate a memory unit and initialize it with 0.DCB
: Allocate a memory unit of bytes and initialize it with the specified data.DCD及 DCDU
: Allocate a memory unit of a word and initialize it with the specified data.DCDO
: Allocate a memory unit of a word, and initialize the contents of each unit to the offset of the unit relative to the static base register.DCFD 及 DCFDU
: Allocate a double-word memory unit and initialize it with double-precision floating point data.DCFS 及 DCFSU
: Allocate a memory unit of a word and initialize it with single-precision floating point data.DCI
: Allocate a memory unit of a byte and initialize it with the specified data. The specified memory unit stores code, not data.DCQ 及 DCQU
: Allocate a double-word memory unit and initialize it with 64-bit integer data.DCW 及 DCWU
: Allocate a half-word memory unit and initialize it with the specified data.DATA
: Use data in code snippets. It is no longer used and is only used for forward compatibility.
LTORG
: Declares the beginning of a data buffer pool (Literal Pool).
Syntax format:LTORG
Usually, the ARM assembly compiler places the data buffer pool at the end of the code segment, that is, before the start of the next code segment, or before the END pseudo-operation.
...
LTORG
data SPACE 4200 ;从当前位置开始分配4200字节的内存单元
END
MAP
: Define the first address of a structured memory table (Storage Map)
Syntax format:MAP expr {,base-register}
FIELD
: Define a data field (Field) in a structured memory table.
Syntax format:{lable} FIELD expr
SPACE
: Allocate a memory unit and initialize it with 0
Syntax format:{label} SPACE expr
data SPACE 500 ;分配500字节的内存单元,并将内存单元内容初始化成0
Assembly control pseudo-operation
Assembly Control pseudo-operations include the following pseudo-operations:
IF、ELSE 及ENDIF
WHILE 及 WEND
MACRO及MEND
MEXIT
IF、ELSE 及ENDIF
: Include a piece of source code in an assembly language program or exclude it from the program based on conditions
IF Version = "1.0"
; 指令
ENDIF
WHILE 及 WEND
: Repeatedly assemble the same or almost the same source code based on conditions
count SETA 1
WHILE count <= 4
count SETA count+1
;code
WEND
MACRO及MEND
: A piece of code defined with MACRO and MEND is called a macro definition body. In this way, the code segment can be called multiple times through macro instructions in the program.
Syntax format
MACRO
{
$label} macroname {
$parameter{
,$parameter}...}
;code
...
;code
MEND
MACRO
$label xmac $p1, $p2 ; 宏的名称为xmac,有两个参数$p1、$p2
MEND
;调用宏
abc xmac subr1, de
MEXIT
: Used to jump out of macro.
Data frame description
Mainly used for debugging
information report
Information reporting (Reporting) pseudo-operations include the following specific pseudo-operations:
ASSERT
INFO
OPT
TTL及SUBT
ASSERT
: In the second pass of the assembly compiler's scan of the assembler, if the conditions are not met, the ASSERT pseudo-operation will report this error message.
INFO
: The INFO pseudo-operation supports reporting diagnostic information during the first or second scan of the assembly process.
OPT
: Through the OPT pseudo-operation, list options can be set in the source program.
TTL及SUBT
:
- The TTL pseudo-op inserts a header at the beginning of each page of the listing file. This TTL pseudo-operation will be applied to each subsequent page until a new TTL pseudo-operation is encountered.
- The SUBT pseudo-operation inserts a subtitle at the beginning of each page of the list file. The SUBT pseudo-operation will be applied to each subsequent page until a new SUBT pseudo-operation is encountered.
Other pseudo operations
CODE16和CODE32
:
- The CODE16 pseudo-operation tells the assembly compiler that the following instruction sequence is a 16-bit Thumb instruction.
- The CODE32 pseudo-operation tells the assembly compiler that the following instruction sequence is a 32-bit ARM instruction.
CODE16
CODE32
EQU
: The EQU pseudo-op defines a character name for numeric constants, register-based values, and labels in programs (PC-based values).
ancd EQU 2 ; 定义abcd符号的值为2
ancd EQU 0x1c, CODE32 ;定义addrl符号的值为绝对地址0x1c,而且该处为ARM指令
AREA
: Define a code segment or data segment.
Syntax format
AREA sectionname{
,attr}{
,attr}...
AREA mycode, CODE, READONLY
ENTRY
:Specifies the entry point of the program.
ENTRY
END
: Tells the compiler that the end of the source program has been reached.
AREA mycode, CODE, READONLY
;code
END
ALIGN
: Make the current position meet a certain alignment by adding patch bytes.
EXPORT和GLOBAL
EXPRORT
Declare a symbol that can be referenced by other files. It is equivalent to declaring a global variable.GLOBAL
Synonyms for yesEXPORT
.
Syntax format
EXPORT symbol
IMPORT
: IMPORT
Pseudo operation tells the compiler that the current symbol is not defined in the original source file, but is defined in other source files. The symbol may be referenced in the original source file, and regardless of whether the original source file actually references the symbol, the symbol will be is added to the symbol table of the source file.
Syntax format
IMPORT symbol
EXTERN
: EXTERN
Pseudo operation tells the compiler that the current symbol is not defined in the source file, but is defined in other source files, and the symbol may be referenced in the source file. If the source file does not actually reference the symbol, the symbol will not be added to the symbol table of the source file.
Syntax format
EXTERN symbol
GET和INCLUDE
: GET
Pseudo operation includes a source file into the current source file and assembles the included file at its current location. INCLUDE
Synonyms for yes GET
.
Syntax format
GET filename
GET c:\file.s
INCBIN
: INCBIN
Pseudo operation includes a file into ( INCLUDE
) the current source file, and the included file will not be assembled.
Syntax format
INCBIN filename
INCBIN data.txt
KEEP
: Tells the compiler to include local symbols in the object file's symbol table.
Syntax format
KEEP symbol
NOFP
: Can prohibit the source program from containing floating-point arithmetic instructions.
Syntax format
NOFP
REQUIRE
: Specify interdependencies between segments.
Syntax format
REQUIRE label
When performing connection processing, if a source file containing a REQUIRE label pseudo-operation is encountered, the source file defining the label will also be included.
RN
: Define a name for a specific register.
Syntax format
name RN expr
ROUT
: Used to define the valid scope of local variables.
Syntax format
{
name} ROUT
When the ROUT pseudo-operation is not used to define the scope of a local variable, the scope of the local variable is the segment (AREA) in which it is located. The scope of the ROUT pseudo-operation is between this ROUT pseudo-operation and the next ROUT pseudo-operation (referring to the ROUT pseudo-operation in the same segment).
ARM assembly language directives
ADR
: This instruction reads a PC-based address value or a register-based address value into a register.
Syntax format
ADR{
cond} register, expr