GNU Arm Assembly pseudocommands (Directive er ctictives)

Source: Internet
Author: User
1. Introduction to GNU Arm Assembly

Any assembly line is structured as follows:

[<Label >:] [<instruction or Directive >}@ comment
[<Tag >:] [<command >}@ comment

In GNU arm assembly, any label ending with a colon is considered as a label, not necessarily at the beginning of a line. The following is a simple example. This assembler defines an "add" function, which returns the sum of two parameters:

.section .text, “x”.global add                      @ give the symbol add external linkageadd:         ADD r0, r0, r1          @ add input arguments         MOV pc, lr              @ return from subroutine                                 @ end of program

2. GNU Arm Assembly pseudocommands

The GNU Arm Assembly pseudocommands start. The following table lists the commonly used compilation artifacts:

Assembly of pseudo commands Description Example
. ASCII "<string>" Inserts a string to the target file, but does not end with null. . ASCII "jnz" @ insert byte 0x4a 0x4e 0x5a
. Asciz "<string>" Similar to. ASCII, but ended with null . Asciz "jnz" @ insert byte 0x4a 0x4e 0x5a 0x00
. Balign <power_of_2>
{, <Fill_value>
{, <Max_padding> }}
Align the following position <power_of_2> . Byte 0x55 @ insert byte: 0x55
. Balign 4, 0 @ insert 3 alignment Bytes: 0x00 0x00 0x00
. Word 0xaa55ee11 @ insert byte: 0x11 0xEE 0x55 0xaa (LSB order)
. Byte <byte1 >{, <byte2> }... Insert byte to target file . Byte 64, 'A' @ inserts the bytes 0x40 0x41
. Byte 0x42 @ inserts the byte 0x42
. Byte 0b000011, 0104 @ inserts the bytes 0x43 0x44
. Code <number_of_bits> Set the number of commands, 16-bit thumb or 32-bit arm . Code 16 @ set the following assembly as the thumb command
. Else Use with. If and. endif  
. End Indicates the end of the Assembly file. The assembler no longer reads the following content.  
. Endif Huai. If used in combination  
. Endm The macro definition is over and used with. Macro.  
. Endr End a loop and use it with. 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 = 0b001010 @ set Adams to 42
. Err Stops compilation if. Err is encountered during assembly.  
. Exitm Exit macro definition halfway  
. Global <symbol> Identifies the symbol to be accessed by other modules (assembly or C) of the program,
It is equivalent to export_symbol in the kernel.
. Global _ my_test_count @ It Can Be r/W by other modules
. Hword <short1 >{, <short2>}
Insert a 16-bit (half-word) value to the target file . Hword 0xaa55, 12345 @ insert byte 0x55 0xaa 0x39 0x30
. 2 byte 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 # include of C  
. 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>}
Defines an assembly macro named name, which has N parameters,
It 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> "}
Start a new section. section_name can be:
. Text: code segment
. Data: initialized Data Segment
. BSS: uninitialized data segment
Flags can be:
A allowable Section
W writable Section
X executable Section
. Section. Text, "X"
. Set <variable_name>,
Set the changed value, which is the same as. equ. . Set Adams, 0x2a @ set Adams to 42
. Space <number_of_bytes>
{, <Fill_byte>}
Reserve the given byte space and set it to 0 or fill_byte. . Space 0x400,0
. Word <word1 >{,< word2> }... Insert a 32-bit word list to the target file Head_ptr:. Word 0 @ head pointer to within buffer (initially zero)
Tail_ptr:. Word 0 @ tail pointer to within buffer (initially zero)
. Word 0 xdeadbeef @ inserts the bytes 0xef 0xbe 0xad 0xde
. 4 byte-42 @ inserts the bytes 0xd6 0xff 0xff 0xff
@ Least significant byte (LSB) Ordering assumed
. Rept <number_of_times> The code block number_of_times is repeatedly executed.
Similarly, end with endr
<Register_name>. req
Register renaming ACC. req R0

3. Arm special characters and syntax

@ Annotator in the code line
# Comments to the entire line
; Statement Separator
# Or $ Direct operand prefix
. Arm
Assemble and use arm commands
. Thumb
Compile the thumb command
. Code16
Compile the thumb command
. Code32
Assemble and use arm commands
. Force_thumb
Use the thumb mode forcibly, even if not supported
. Thumb_func
Mark entry point as thumb coded (Force BX entry)
. Ltorg
Start a new literal pool (Text pool: The area embedded in the code to store constants)
0 Octal
0x or 0x Hexadecimal
0b or 0b Binary
No Leading Character Decimal

. Data Mark the subsequent statement into the data segment of the target file
. Text
Mark the code segment that puts subsequent statements into the target file
. Extern symbol
Introduce symbols from other modules, similar to extern in C
. Skip expression
Number of bytes specified by Skip expression in the target file
Buffer:. Skip 512 @ buffer of 512 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: 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.