What is hard to understand during the analysis of arm assembler programs is his pseudo operations, macro commands, and pseudo commands. I encountered a lot of questions when reading Vivi, so I would like to summarize the false operations, macro commands, and pseudo commands in the pilot program, **************************************** ************* 1. Get option. s // Get and include functions are the same Function: Introduce a compiled file. Format: Get filename The file name introduced during the fiename assembly can have a path name. The GET symbol is useful for macro definition, EQU symbol, and storage ing during assembly. After file assembly is introduced, assembly starts from the GET symbol. In the imported file, you may have a GET symbol before introducing other files. The GET symbol cannot be used to import the target file. **************************************** ************* Ii. intpnd equ 0x01e00004 // EQU can be replaced by "*". Pay attention when reading the source program. Function: assign a symbolic name to a numeric constant. Format: name EQU expression The name indicates the name. Fixed values related to the Expression register or program. Use EQU to define a constant, which is the same as # define to define a constant in C. For example: num EQU 2; Number 2: Assign the num symbol **************************************** ************* Iii. GBLL THUMBCODE [{CONFIG} = 16 Thumbcode setl {TRUE} CODE32 | Thumbcode setl {FALSE} ] [THUMBCODE CODE32; for start-up code for Thumb mode ] // [= IF, | = ELSE,] = ENDIF. CODE32 indicates that all operations are in the ARM state. These are all pseudo operations. This section defines the value of THUMCODE and then determines whether your program is in the ARM or THUM state. **************************************** ************* Iv. Macro $ Handlerlabel handler $ handlelabel $ Handlerlabel Sub sp, SP, #4; Decrement Sp (to store jump address) Stmfd SP !, {R0}; push the work register to stack LDR r0, = $ handlelabel; load the address of handlexxx to R0 LDR r0, [R0]; load the contents (service routine start address) of handlexxx STR r0, [Sp, #4]; store the contents (ISR) of handlexxx to stack Ldmfd sp !, {R0, pc}; POP the work register and pc (jump to ISR) MEND // MACRO ...... MEND Function: indicates the macro definition. Format: MACRO Macro_prototype MEND The macro expression format is as follows: {$ Label} macroname {$ parameter {, parameter2 }...} Where: $ Label parameter, which is replaced by the given symbol in macro usage. The Macroname macro name does not necessarily start with a command or symbol name. $ Parameter is an alternative parameter in macro usage. Format: $ parameter = "default value" In a macro, the parameter $ parameter is used like a variable. When referenced by a macro, it is assigned a new value. The parameter must be differentiated by the "$" symbol. $ Label is useful when a macro defines an internal symbol and can be considered as a macro parameter. Use the '|' symbol as a variable that uses the default value of a parameter. If a space character string is used, this variable is skipped. It is useful to define an internal flag as a flag with a Suffix in the macro definition of an internal flag. If there is not enough space in the extension, it can be used as a separator between the parameter and the subsequent text or between the parameters, but the dot cannot be used between the text and subsequent parameters. Macro can define the range of local variables. Macros can also be nested. Example: MACRO $ Label xmac $ p1, $ p2 LCLS err $ Labell, loopl BGE $ pl $ Labell, loop2 BL $ p1 BEG $ p1 BEG $ labell, loop2 MEND **************************************** ************* V. $ and $ // $ Replace temporary variables. If the program needs to use the character $, it is represented by $. Generally, $ between two | does not indicate replacement of variables, however, if the | line is in double quotation marks, the variable is replaced. Use "." To separate the usage of variable names, Gw.str1 Gw.str2 STR1 SETS "AAA" STR2 SETS "BBB $ STR1.CCC" // The STR2 value after compilation is bbAAACCC **************************************** ************* 6. IMPORT Main; The main entry of mon program // This pseudo operation tells the compiler that the current symbol is not defined in this file. It may be referenced in this source file, regardless of whether the source file uses the symbol, this symbol will be added to the source file. Format: IMPORT symbol {[WEAK]} The name of the symbol referenced by the symbol. It is case-sensitive. If [WEAK] specifies this option, the compiler will not report an error if the source file of the symbol is not defined. It works the same as EXTERN. The difference is that if this source file does not actually reference this symbol, it will not be added to the symbol table of this source file. **************************************** ************* VII. AREA Init, CODE, READONLY ENTRY // Function: indicates the assembler to compile a new code or data zone. Format: The name of a specific segment. It must start with a number. Otherwise, an error is reported, for example, | 1_Data-Area |. Some names are retained, such as: | C $ code | a code segment that has been used by the C compiler or connected to the C library. The following attributes are valid: ALIGN = expression By default, the AOF segment is aligned by four bytes, and the expression can be 2 ~ An integer between 31, which is aligned by 2 (supermarked as expression) bytes. For example, espression is equal 10. This segment is aligned at 1 kb. CODE specific machine commands. The default value is READONLY. COMDEF common segment definition. This AOF segment may include code and data, but must be different from other segment names. COMMON data segments. No additional code and data need to be commented out. Generally, the linker initializes the data to zero. DATA contains DATA but does not contain commands. The default value is READWRITE. INTERWORK indicates that the code segment can be used with the ARM/Thumb interworking function. NOINIT indicates that the data segment can be initialized to zero and only contains the indicator. PIC indicates to locate the independent segment, which can be executed at any address without modification. READONLY indicates that the segment is readable and writable. There must be at least one AREA indicator during assembly. The AREA symbol can be used to differentiate source programs, but must be unique. Generally, an independent AOF segment is required as a code or data segment. A large program can be divided into multiple code segments. The AOF segment can define the range of local labels and can use the ROUT symbol. If no AREA indicator is defined, the assembler generates an AOF segment named |$ $ | and a Diagnostic message, the error information generated due to the lack of indicator will be restricted, but it may not be compiled successfully. **************************************** ************* 8. LTORG // LTORG puts a literal pool in the place where the command appears. This pool is often used in ARM assembly. Ldr r0, = instruction load the address instruction to r0 In this case, the compiler converts ldr into mov or mvn commands as much as possible. If the conversion fails, an ldr command will be generated to read the value of instruction from a memory area that stores constants through the relative address of the pc. This memory area is a text pool. Generally, the text pool is placed after the END command. However, if the offset address is greater than 4 K space, the ldr command will fail (because the relative offset address of ldr is 12-bit ). at this time, use LTORG to place it near the ldr command that will cause an error to solve this problem. The compiler collects unallocated ldr values and places them in this text pool. . Therefore, you must use LTORG to explicitly add a text pool to the code segment within the range of 4 kb before and after the LDR command. **************************************** ************* 9. LDR r0, = WTCON; watch dog disable LDR r1, = 0x0 Function: Read a 32-bit constant or address to a register. Format: LDR {condition} register, = [expression | Label-expression] Where: Conditional code. Registers read by register. Expression numeric constant: If the numeric constant is within the range of MOV or MVN commands, the assembler will generate appropriate commands; If the number is not within the range of MOV or MVN commands, the assembler writes the constant to the program and reads it using the program-related LDR pseudo command. The offset between PC and the constant cannot exceed 4 kb. The Label-expression Program-related or external expression. The assembler stores it in the constant Library (called the literal pool) after the program, and reads it using the program-related LDR pseudo command. The offset between the PC and the constant cannot exceed 4 kb. The use of LDR pseudo commands has two purposes: Convert the number of immediate records that cannot be read by MOV and MVN commands into constants for reading. Read a program-related or external expression into the register. Example: LDR R1, = 0 xfff LDR R2, = place **************************************** ************* 10. DCD 0x11110090 ; Bank0 = OM [1:0], Bank1 ~ Bank7 = 16bit, bank2 = 8bit; // DCD or "&" Function: allocate one or more words, starting from the 4-byte boundary. Format: {Label} DCD expression {, expression }... Where: Expression can be: A mathematical expression; A program-related expression. If you use the DCD symbol in the Thumb Code to define labeled DATA, you must use the DATA symbol. The DCD symbol inserts 3-byte null characters before the first byte. You can use the DCDU symbol if you do not need to align them. Example: Datal DCD 1, 5, 20 Data2 DCD mem06 Data3 DCD glb + 4 **************************************** ************* 11. Align // Function: starts with a word boundary. Format: Align {expression {, offset-expression }} Where: Expression 2 (0) to any number of power between 2 (31), currently based on 2 (n) bytes. If this parameter is not specified, align is aligned by words. Offset-expression defines the byte offset of the method specified by expression. Use the align symbol to ensure that the program is aligned correctly. For the thumb address, use the align symbol to ensure its word-aligned. For example, the ADR thuub pseudocommand can only read the word-aligned address. Use the alige symbol when a data definition is displayed in a code segment. When you use data delimiters (DCB, dcw, dcwu, DCDU, and %) in the code segment, the program counter PC is not necessarily aligned by word. The assembler inserts 3 bytes into the next instruction to ensure: Aligned by words in arm State; In the thumb state, the image is aligned by half-character. In the thumb state, you can use align2 to align the thumb code with half words. In the ALIGN status, you can also make full use of the Cache of some ARM processors. For example, ARM940T has a 4-character Cache per line, and ALIGN16 is used for 16 bytes to maximize the usage of the Cache. **************************************** ************* 12. ^ _ ISR_STARTADDRESS // MAP and "^" MAP is used to define the first address of a structured memory table (StorageMAP. In this case, the position counter {VAR} (the built-in variable of the assembler) of the memory table is set to this address value. MAP can be replaced by "^. Syntax: MAP expr {, base-register} Expr is a numeric expression or a label defined in the program. Base-register is a register. When the command does not contain Base-register, expr is the first address of the structured memory table. In this case, the location counter {VAR} of the memory table is set to this address value. When the command contains this item, the first address of the structured memory table is the sum of the expr and Base-register content. Instructions for use: MAP and FIELD pseudo operations are used together to define a structured memory table structure. Example: MAP pseudo operation MAP fun; fun is the first address of the memory table MAP 0x100, R9; the first address of the memory table is R9 + 0x100 **************************************** ************* 13. handlereset #4 Handleundef #4 Handleswi #4 // Field and "#" Field is used to define the data fields in a structured memory table. Field can be replaced. Syntax: {label} field expr {Label} is optional. When the command contains this item, the label value is the value of the position counter {var} of the current memory table. After the assembly compiler processes this field pseudo operation. The value of the memory table counter is added with expr. expr, which indicates the number of bytes occupied by the current data field in the memory. Instructions for use: map and field pseudo operations are used together to define a structured memory table structure. The map pseudo operation defines the first address of the memory table. The field pseudo operation defines the length of the data field in the memory table, and can specify a label for each data field. Other commands can reference this label. The base-registe register value team in the map pseudo operation uses the data fields defined by all subsequent field pseudo operations by default, until a new map pseudo operation containing the base-registe item is encountered, it is worth special attention that the map pseudo operation and field pseudo operation only define the data structure, they do not actually allocate memory units. There are three memory tables defined by the combination of MAP and field pseudo operations: Memory tables based on absolute addresses, memory tables based on relative addresses, and memory tables based on PCs. Example: memory table based on absolute address Use a pseudo-operation sequence to define a memory table whose first address is fixed address 8192 (0X2000). The memory table contains five data domains. The Consta length is 4 bytes, The constb length is 4 bytes, the x length is 8 bytes, the y length is 8 bytes, and the string length is 16 bytes. This memory table is an absolute address-based memory table. MAP 8192; // The first address of the memory table 8192 (0x2000) Consta FIELD 4; // The consta length is 4 bytes and the relative position is 0. Constb FIELD 4; // The length of constb is 4 bytes and the relative position is 4. X field 8; // X is 8 bytes long and the relative position is 8. Y field 8; // y is 8 bytes long and the relative position is 16. String FIELD 16; // String is 16 bytes, relative location is 24 In the instruction, you can reference the data fields in the memory table in this way; LDR R0, consta; // The command that loads the memory corresponding to the consta address to R0 can only access the data domain in the range of 4 kb before and after the LDR command. Example: memory table with relative absolute address The following pseudo-Operation Sequence defines a memory table with its first address 0 and R9 registers worth sum. The memory table contains five data domains. These tables are called memory tables with relative addresses. MAP 0, R9; // The value of R9 In the first address register of the memory table Consta FIELD 4; // The consta length is 4 bytes and the relative position is 0. Constb FIELD 4; // The length of constb is 4 bytes and the relative position is 4. X Field 8; // X is 8 bytes long and the relative position is 8. Y Field 8; // y is 8 bytes long and the relative position is 16. String Field 16; // string is 16 bytes, relative location is 24 The following command can be used to access data with a address range of more than 4 kb; ADR R9, field; // pseudocommand LDR R5, constb; // equivalent to LDR R5, [R9, #4] Here, the data in the memory table is relative to the content of the R9 register, rather than a fixed address. By specifying the value of different base address registers in LDR, the defined memory table structure can have multiple instances in the program. You can use the LDR command multiple times to implement different program instances. Example: PC-based memory tables Data Space 100; // allocate a memory unit of 100 bytes and initialize it to 0 Map data; // The first address of the memory table is the memory unit of datastruc. Consta field 4; // The Consta length is 4 bytes and the relative position is 0. Constb field 4; // The length of constb is 4 bytes and the relative position is 4. X Field 8; // X is 8 bytes long and the relative position is 8. Y Field 8; // y is 8 bytes long and the relative position is 16. String Field 16; // string is 16 bytes, relative location is 24 The following command can be used to access data with a range of no more than 4 kb; LDR R5, constb; equivalent to LDR R5, [PC, offset] **************************************** ************* |