Chapter 4 Arm Assembly Language Programming
4.1 arm pseudocommands
There are 6 types of pseudocommands: symbolic definition pseudocommands, data definition pseudocommands, assembly control pseudocommands, framework Description pseudocommands, information reporting pseudocommands, and other pseudocommands.
4.1.1 symbolic definition pseudocommand: used to define variables in arm assembler, assign values to variables, and define Register names.
Gbla, gbll, and gloud declare global variables
Declare local variables by llinoleic, lcll, and lcls
Seta, SETl, and sets assign values to variables
Rlist register list definition name
Register definition name of the CN coprocessor
CP coprocessor definition name
Register definition name with DN and Sn as vfp (floating point Architecture)
FN is the definition name of the FPA floating-point register.
Gbla, gbll, gstrap
Gbla declares a global numeric variable and initializes it to 0.
Gbll declares a Global Logical variable and initializes it to {false}
Gsung declares a global string variable and initializes it as an empty string ""
Example
Gbla objectsize; declare a global numeric variable, initialized to 0
Objectsize Seta 0xff; assign the variable objectsize to 0xff
Space objectsize; reference this variable
Gbll statusb; declare a Global Logical variable statusb
Statusb SETl {true}; assign true to the logic variable statusb
Ltls, lcll, and lcls
Ltls declares a local numeric variable and initializes it to 0.
Lcll declares a local logical variable and initializes it to {false}
Lcls declares a local string variable and initializes it as an empty string.
Seta, SETl, and sets
Seta assigns a value to the numeric variable
SETl assigns values to logical variables
Sets to assign values to string variables
G message; defines a global string variable.
Message sets "hello! "; Assign values to the variable string
Rlist
Rlist defines a name for a general register list
Context rlist {R0-R6, R8, R10-R12, R15}; Define register list name as context
CN
CN defines the name of a coprocessor register
Power CN 6; define the name of the coprocessor register 6 as power
CP
CP defines a name for a coprocessor
Dmu cp 6; Define coprocessor 6 as DMU
DN, Sn
DN is a dual-precision VFP register (numbered 0 ~ 15) Definition name
Sn is a single-precision VFP register (numbered 0 ~ 31) Definition name
Height DN 6; VFP dual-precision register 6 is defined as height
Width Sn 16; the name of VFP single precision register 16 is defined as width
FN
FN is a FPA floating-point register (numbered 0 ~ 7) Definition name
Fat FN 5; Define floating point register 5 as fat
4.1.2 data definition Directive
Ltorg declares the beginning of a Data Buffer Pool
Map defines the first address of a memory table
Field defines the data fields in the memory table
Space allocates a memory unit and initializes it with 0
One-byte memory unit allocated by DCB
DCD and DCDU allocate memory units with one word
Dcdo allocates a memory unit with a single field and is initialized as an offset.
Dcfd and dcfdu allocate one or two-character memory units and initialize them with double-precision floating point data.
DCFS and dcfsu allocate memory units of one word and initialize them with single-precision floating point data.
DCI allocates memory units of one byte.
Dcq and dcqu allocate two-character memory units
Dcw and dcwu allocate a half-Word Memory Unit
Data is no longer used in code segments.
Ltorg
Ltorg is used to declare the beginning of a data buffer pool.
Area example, code, readonly
Start BL func1
Func1; subroutine
; Code
LDR R1, = 0x55555555; LDR R1, [PC, # offest to literal Pool 1]
; Code
MoV PC, LR; end of subroutine
Ltorg; define data buffer pool & 55555555
Data Space 4200; Allocate 4200 bytes of memory units from the current position
End; the default data buffer pool is empty.
Map
Map defines the first address of the memory table, and is used with the field to define the structure of the structured memory table. ^ Is the synonym of map.
Map 0x80, R9; the first address of the memory table is R9 + 0x80
Field
Field defines the data fields in the memory table. # Is a synonym for field. Map and field only define the data structure and do not allocate memory units.
Map 0; memory table's first address is 0
Consta field 4; Consta length is 4 bytes, relative position is 0
Constb field 4; constb length is 4 bytes, relative position is 4
X Field 8; x length 8 bytes, relative position 8
Y Field 8; y length is 8 bytes, relative position is 16
String Field 256; String Length: 256 bytes; relative position: 24
LDR R6, Consta; reference data fields in the memory table
Map 4096; the first address of the memory table is 4096 (0x1000)
Consta field 4; Consta length is 4 bytes, relative position is 0
Constb field 4; constb length is 4 bytes, relative position is 4
X Field 8; x length 8 bytes, relative position 8
Y Field 8; y length is 8 bytes, relative position is 16
String Field 256; String Length: 256 bytes; relative position: 24
MoV r9,# 4096
LDR R5, [R9, constb]; read the data domain constb in the memory table to R5.
In the arm-thumb command, R9 is usually used as the static base address register.
Map 0, R9; the first address of the memory table is R9 + 0
Consta field 4; Consta length is 4 bytes, relative position is 0
Constb field 4; constb length is 4 bytes, relative position is 4
X Field 8; the length of X is 8 bytes, and the relative position is 8
Y Field 8; y is 8 bytes in length and the relative position is 16.
String Field 256; String Length 256, relative position 24
You can use the following commands to easily address data larger than 4 kb.
ADR R9, datastart; the ADR command reads the Pc value or register value to the Register, which is calculated based on the PC value.
LDR R5, constb; equivalent to LDR R5, [R9, #4]
Datastruc space 280; Allocate 280 bytes of memory units
Map datastruc; the first address of the memory table is the memory unit of datastruc.
Consta field 4; Consta length is 4 bytes, relative position is 0
Constb field 4; constb length is 4 bytes, relative position is 4
X Field 8; the length of X is 8 bytes, and the relative position is 8
Y Field 8; y is 8 bytes in length and the relative position is 16.
String Field 256; String Length 256, relative position 24
LDR R5, constb; equivalent to LDR R5, [PC, offest]
When the operand in the field pseudo command is 0, the label indicates the address of the current memory unit.
Space
Space is used to allocate a memory unit and initialize it with 0. % Is a synonym for space.
Datastruc space 1000; Allocate 1000 bytes and initialize the memory unit content to 0
DCB is used to allocate a continuous byte memory. = Is a synonym for DCB
{Label} DCB expr {, expr} {, expr }...
Where:
Label the start address of the memory block.
Expr can be-128 ~ A value or string of 255. The number of bytes allocated by the memory is determined by the number of expr.
Nullstring DCB "Null String", 0; construct a string ending with null
DCD, DCDU, dcdo, dcfd, dcfdu, DCFS, dcfsu, DCI, dcq, dcqu, dcw, and dcwu can be referenced.
4.1.3 Assembly control pseudoinstructions
If, else, And endif
While and Wend
Macro and mend
Mexit
If, else, And endif
If, else, And endif are used to select
If version = "1.0"
; Command
; Pseudoinstructions
Else
; Command
; Pseudoinstructions
Endif
While and Wend
While and Wend Loops
Count Seta 1; set the initial value of the cyclic count variable count to 1.
While count <= 4; number of loops controlled by conut
Count Seta count + 1; Add the cyclic count variable to 1
; Code
Wend
Macro and mend
Macro and mend definition macros
Macro; macro definition starts
$ Label xmac $ P1, $ P2; the macro name is xmac and has two parameters: $ P1 and $ P2.
; Macro label $ lable can be used to construct other label names in the macro definition body
; Code
$ Lable. loop1; Code; $ lable. loop1 indicates the internal label of the macro.
; Code
BGE $ label. loop1
$ Label. loop2; Code
BL $ P1; parameter $ P1 is the name of a subroutine
Bgt $ label. loop2
; Code
ADR $ p2
; Code
Mend; macro definition ends
; Macro calls in the program
ABC xmac subr1, de; calls a macro through the macro name xmac, in which the macro label is ABC,
; Parameter 1 is subr1, parameter 2 is de
; Macro expansion results after the program is compiled
; Code
ABC. loop1; Code; Replace $ label with the actual label value abc
; Code
Bge abc. loop1
ABC. loop2; Code
BL subr1; the actual value of parameter 1 is subr1
; Code
ADR de; the actual value of parameter 2 is de
Mexit
Mexit is used to jump out of the macro
Macro
$ ABC macroabc $ P1, $ p2
; Code
While condition1
; Code
If condition2
; Code
Mexit; jump out of the macro
Else
; Code
Endif
Wend
; Code
Mend
4.1.4 false instructions for information reporting
When the assert condition is invalid, the alarm information is displayed.
Info report information
Opt setting list options
TTL and subt insert titles and subtitles
4.1.6 other pseudocommands
Allgn
Area
Code16 and code32
End
Entry
Equ
Export or global
Extern
Get or include
Import
Incbin
Keep
Nofp
Require
Require8 and perserver8
Rn
Rout
Allgn
Allgn specifies alignment
Area cacheable, code, allgn = 3; specify that the following quality is 8-byte alignment
Rout1; Code
; Code
MoV PC, LR; after the program jumps, it becomes 4-byte alignment
Allgn 8; specify that the following commands are 8-byte aligned
Rout2; Code
Area
Area defines a code segment or data segment
Area example, code, readonly; defines a code segment named example and its attribute is readnoly.
Code16 and code32
Code16 indicates that the subsequent command is the thumb command
Code32 indicates that the subsequent commands are arm commands.
End
End indicates the end of the source program.
Entry
Entry specifies the program entry point.
Equ
Equ is used to get an alias. * is the synonym, which is equivalent to # define in C.
ABCD equ 2; Define ABCD to represent 2
Addr1 equ 0x1c, code32; defines addr1 as the absolute address 0x1c, and this command is an arm command
Export and global
Export declares that a symbol can be referenced by other files, which is equivalent to declaring a global variable. Global is a synonym for export.
Area example, code, readonly
Export doadd; the following function name doadd can be referenced by other source files
Doadd add r0, R0, r1
Extern
Extern declares a symbol defined in other source files.
Area example, code, readonly
Extern _ cpp_initialize [Weak]; if the C ++ library is connected, the function _ cpp_initialize address is read.
LDR r0, _ cpp_initialize
CMP r0, 0;
Beq nocplusplus; skip to nocplusplus if the C ++ library is not connected
Get and include
Get includes a file to the current file. Include is a get synonym.
Area example, code, readnoly
Get file1.s; contains the source file file1.s
Get C:/project file/file2.s; contains the source file file2.s, which can contain spaces in the path
Import
Import external definition symbols
Incbin
Incbin includes the file into the current file, but the contained file is not assembled.
Area example, code, readonly
Incbin file1.dat; contains the file file1.dat
Incbin C:/projecfile/file2.txt contains the file file2.txt, which cannot contain spaces.
Keep
Keep includes local symbols in the symbol table of the target file.
Nofp
Nofp disables floating-point operations
Prequire
Dependencies between specified segments in prequire
Require8 and preserver8
Require8 requires 8-byte data stack alignment in the current Code
Preserve8 requires 8-byte data stack alignment in the current Code
Rn
Rn defines a register name, that is, changing the name.
Rout
Rout defines the valid range of local variables