Embedded study notes (8) ARM assembly pseudo-instructions

The meaning of directive

Pseudo-instructions are not instructions. The fundamental difference between pseudo-instructions and instructions is that machine code will not be generated after assembly.

The significance of pseudo-instructions is to guide the assembly process.

The pseudo-instruction is related to the specific assembler. We use the gnu tool chain, so learn the assembly pseudo-instruction under gnu

Some symbols in gnu assembly

@ is used for comments.

: A label ending with a colon

. The dot represents the address of the current instruction in gnu assembly (b. This sentence represents an infinite loop)

# Add # or $ before the immediate number, indicating that this is an immediate number

Commonly used gnu directives

.global_start @Give _start an external link attribute, which means that _start can be called in other files.

.section.text @Specify the current section as a code section

.ascii .byte .word These three most commonly used are equivalent to declaring variables as char byte int

.short .long .quad .float .string @definition data

IRQ_STACK_START:

.word 0x0badc0de

Equivalent to unsigned int IRQ_STACK_START = 0x0badc0de;

.align4 @ align by 16 bytes (2exp4)

.balignl 16 0x1234567f @16 byte alignment padding

b indicates bit filling; align indicates alignment; l indicates long, filled in units of 4 bytes; 16 indicates 16-byte alignment; 0xdeadbeef is the raw material for filling.

0x00000008: .balignl 16, 0xdeadbeef

0x0000000c 0xdeadbeef

0x00000010: next instruction

Occasionally used gnu directives

.end @ marks the end of the file

.include @header file includes

.arm / .code32 @ declares the following as arm instructions

.thumb / .code16 @declare the following as thumb instructions

The most important directives

ldr Large range address load instruction

adr small range address load instruction

adrl mid-range address load instruction

nop no operation

There is an ldr instruction in ARM, and an ldr pseudo-instruction

Generally, the ldr pseudo-instruction is used instead of the ldr instruction (because the use of the ldr instruction also needs to consider the legality of the immediate value, and the use of the ldr pseudo-instruction will help in the assembly process)

ldr command: ldr r0, #0xff

ldr pseudo-instruction: ldr r0, =0xfff1 @ involves legal/illegal immediate data, and involves ARM literal pool

The difference between adr and ldr: the address loaded by ldr is determined at link time, and the address loaded by adr is determined at runtime; so you can judge whether the current program is running at the address specified at link time by comparing the addresses loaded by adr and ldr.

  For more embedded study notes and practical projects, click here to get free

Guess you like

Origin blog.csdn.net/m0_70888041/article/details/132616553