GNU ARM Assembler pseudo-directive (assembler directives)

Source: Internet
Author: User
1. Introduction to the GNU ARM Assembly

Any assembly line is structured as follows: [<label>:] [<instruction or DIRECTIVE>} @ Comment
[< label;:] [< instruction;} @ Comment

In the GNU ARM assembly, any end of a colon is considered to be a label, not necessarily the beginning of a line. Here is a simple example of the assembler that defines an "add" function that returns the two parameters and:[CPP]View plain Copy. Section. Text, "X". Global add @ give the symbol add external linkage add:                                    Add R0, R0, r1 @ Add input arguments MOV pc, LR @ return from subroutine @ End of Program
2. GNU Arm Assembly pseudo-directive

GNU Arm Assembly pseudo-directives all begin with. Common Assembly pseudo-means are as follows:

Assembly Pseudo-Directives Describe Example
. ASCII "<string>" Inserts a string into the destination file, but does not end with null . ASCII "JNZ" @ Insert byte 0x4a 0x4E 0x5A
. Asciz "<string>" Similar to. ASCII, but ends with null . Asciz "JNZ" @ Insert byte 0x4a 0x4E 0x5A 0x00
. balign <power_of_2>
{,<fill_value>
{, <max_padding>}}
Make the following position <power_of_2> align . Byte 0x55 @ Insert byte: 0x55
. balign 4,0 @ Insert 3 aligned bytes: 0x00 0x00 0x00
. Word 0xaa55ee11 @ Insert byte: 0x11 0xEE 0x55 0xAA (LSB order)
. Byte <byte1> {, <byte2>} ... Insert byte to destination file . Byte, ' A ' @ Inserts the bytes 0x40 0x41
. Byte 0x42 @ Inserts the byte 0x42
. Byte 0b1000011, 0104 @ Inserts the bytes 0x43 0x44
. Code <number_of_bits> Set the number of instruction bits, 16-bit thumb or 32-bit arm . code 16 @ Set the following assembly as thumb instructions
. else Use with. if and. endif
. end End of symbol assembly file, assembler no longer reads back content
. endif If used in conjunction with the.
. endm Flag macro definition end, used in conjunction with. macro
. Endr End a loop, using the. rept and. IRP
. equ <symbol Name>, <value> Set the value of a symbol . Equ Adams, (5 * 8) + 2 @ set Adams to 42
. Set Adams, 0x2A @ set Adams to 42
Adams = 0b00101010 @ set Adams to 42
. err Assembly when you encounter. Err, stop compiling
. exitm Exit macro Definition Halfway
. Global <symbol> Identity symbol is accessed by other modules of the program (assembly or C),
Equivalent to Export_symbol in kernel
. Global _my_test_count @ It can be r/w by other modules
. Hword <short1> {, <short2>}
...
Insert 16-bit (half-character) value to the destination file . Hword 0xaa55, 12345 @ Insert byte 0x55 0xAA 0x39 0x30
.2byte 0X55AA, 1 @ Insert byte 0xAA 0x55 0xFF 0xFF
@ Least significant Byte (LSB) ordering assumed
. If <logical_expression> Use with. endif
. ifdef <symbol> Use with. endif
. ifndef <symbol> Use with. endif
. include "<filename>" Similar to C's # include
. IRP <param> {, <val_1>}
{, <val_2>} ...
Repeats a block of code, once for each value
In the value list. Mark the end of the block
Using a. endr directive. In the repeated code block,
Use \<param> to substitute the associated
value in the Value list.
. macro <name> {<arg_1}
{, <arg_2>} ... {, <arg_n>}
Define a compilation macro called Name, which has n parameters,
and must end with. Endm.
. macro Shiftleft A, b
. If \b < 0
MOV \a, \a, ASR #-\b
. exitm
. endif
MOV \a, \a, LSL #\b
. endm
. Section <section_name>
{, "<flags>"}
To start a new section, the Section_name can be:
. Text: Code snippet
. Data: Initialized Segments
. BSS: Uninitialized data segments
The flags can be:
A allowable section
W writable section
X executable section
. section. Text, "X"
. set <variable_name>,
<variable_value>
Sets the value of the change, as with the. equ . Set Adams, 0x2A @ set Adams to 42
. Space <number_of_bytes>
{, <fill_byte>}
Reserve a given byte space and set to 0 or fill_byte . Space 0x400,0
. Word <word1> {, <word2>} ... Insert a 32-bit word list to the destination file Head_ptr:. Word 0 @ Head pointer to within buffer (initially zero)
Tail_ptr:. Word 0 @ tail pointer to within buffer (initially zero)
. Word 0xDEADBEEF @inserts the bytes 0xEF 0xBE 0xAD 0xDE
.4byte-42 @ Inserts the bytes 0xd6 0xFF 0xFF 0xFF
@ Least significant Byte (LSB) ordering assumed
. rept <number_of_times> Repeat code block number_of_times times, with C for
Similar to the end of Endr
<register_name>. req
<register_name>
Register Rename Acc. req R0

3. Arm special characters and syntax

@ Comment symbols in line of code
# Full line Comment symbol
; Statement Detach symbol
#或 $ Prefix of direct operand
. arm
assembly using ARM directives
. Thumb
Assembly using Thumb Instructions
. code16
Assembly using Thumb Instructions
. code32
assembly using ARM directives
. force_thumb
Force use of thumb mode even if not supported
. thumb_func
Mark entry point as thumb coded (Force BX entry)
. ltorg
Start a new literal pool (text pool: an area embedded in code to hold constants)

0 8 binary
0x or 0X 16 binary
0b or 0 B Binary
No leader character 10 binary

. Data Identifies the subsequent statement into the destination file data segment
. text
Identifies the code snippet that puts the subsequent statement into the destination file
. extern symbol
Introduce symbols from other modules, like extern in C
. Skip Expression
The number of bytes specified by skip expression in the destination file
Buffer:. Skip @Buffer of bytes, uninitialised


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.