This article mainly introduces the principles of GNU ARM assembly grammar and operation analysis. The article introduces the example code in detail, which has certain reference value for everyone's learning or work. Friends who need it can refer to it.
There are two styles of ARM assembly source programs:
- ARM officially recommends style, all instructions are capitalized. Commonly used in IDE under Windows.
- GNU style assembly style, all instructions are lowercase. Commonly used in Linux-related tools.
Comment symbols:
The annotation symbol used in GNU arm assembly is the @ symbol. Similarly, the two types of annotation methods in the C language are also supported in GNU arm assembly.
Macro definition:
In the GNU arm assembler, you can use pseudo-operation .equ to define macros, but also support macros defined in the #define form in the C language. #define is usually used to define macros in actual programming. In addition to supporting #define macros, GNU arm assembly also supports usage of conditional compilation and #include.
Label number:
Symbols ending with colons in GNU arm assembly are called labels. The label essentially represents the address.
Commonly used pseudo-operations:
- .global: used to declare labels as external link attributes, that is, they can be used by other files.
- .extern: used to declare the label as an external label, which is similar to the extern keyword in C language.
- .: Used to represent the address of the current instruction, often used in the implementation of a dead loop, such as b.
- .ascii, .word, .short, .byte: used to define data. Note that the .ascii pseudo-operation needs to add \0 after defining a string.
- .section: Use custom segments. The predefined segment names of GNU arm assembly are .text .data .bss
- .align :.align n uses 2^n byte alignment. For example, .align 2 adopts 2^2=4 byte alignment. Specifically, the address of the instruction after .align needs to be aligned 2^n bytes.
- .balign[wl]: .balign[wl] n, 0xXXXXXXXXXXXX means using n byte alignment and using several bytes of padding based on [wl]. If there is no w or l, byte padding is used; if it is w, double byte padding is used; if it is l, 4 byte padding is used.
- .end: indicates the end of the entire assembly program
- .arm/.code 32: means that the ARM instruction is used
- .thumb/.code 16: means that the Thumb command is used
- .comm: Used to apply for a memory space in the bss segment. This pseudo-instruction allows the size of the bss segment to not occupy the size of the executable file. Just use .comm to record how much space is needed.
The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.