Based on ARM Cortex-M3 microcontroller (STM32 series) basic knowledge (4) - ARM assembly language programming

Thumb pseudo-instruction

insert image description here

LDR (Large Range Address Read Pseudo-instruction)

insert image description here
insert image description here
insert image description here

ARM assembler structure

AREA: Used to define a code segment or data segment pseudo-operation.

CODE16: Used to tell the assembler that the instruction sequence that follows is a 16-bit Thumb instruction.

ARM or CODE32: Used to tell the assembler that the instruction sequence that follows is a 32-bit ARM instruction.

The GBLA pseudo-op is used to define a global numeric variable and initialize it to 0.
insert image description here
In an assembly language program, use the AREA pseudo-operation to define a segment, and describe the relevant attributes of the defined segment. This example defines aSnippet called InitProperty is read-only.The ENTRY pseudo-operation identifies the entry point of the program, followed by the instruction sequence, and the end of the program is the END pseudo-instruction, which tells the compiler the end of the source file. Each assembly program segment must have an END pseudo-operation to indicate the code segment. end of.
insert image description here
insert image description here
insert image description here
insert image description here

Notice

insert image description here
insert image description here

example

insert image description here

1. AREA (section definition directive)

insert image description here

example

insert image description here

2. CODE16、CODE32

insert image description here

3. ENTRY (program entry indication pseudo-instruction)

insert image description here

4. END (Program end pseudo-instruction)

insert image description here

5. EQU (equivalent pseudo-instruction)

insert image description here

6. EXPORT (global label declaration directive)

The EXPORT pseudo-operation is used to declare a global label in the program that can be referenced in other files. EXPORT can be replaced by GLOBAL. Labels are case-sensitive in the program.
insert image description here

7. IMPORT (label reference and add declaration directive)

insert image description here

8. Data Definition Pseudo-Operations (DCB, DCD, DCW)

insert image description here
insert image description here

assembly language programming

insert image description here

The steps to create an assembly language program are as follows:

insert image description here

example

insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here

C program to achieve the sum of 5 integers

insert image description here
insert image description here

Data block copy application example

insert image description here

 AREA reset,CODE,READONLY
num    EQU  20                         ;设置复制的字数
       ENTRY                           ;程序入口
start  LDR  r0,=src                    ;r0指向源数据块首地址
       LDR  r1,=dst                    ;r1指向目标数据块首地址
       MOV  r2,#num                    ;r2复制的字数
       MOV  sp,#0x400                  ;设置堆栈指针,用于保存工作寄存器数值
blockcopy
       MOVS r3,r2,LSR #3               ;需要进行的以8个字为单位的数据复制
       BEQ  copywords                  ;对剩余不足8个字数据,跳转到copywords
                                       ;以字为单位复制
       STMFD sp!,{
    
    r4-r11}              ;保存工作寄存器
octcopy
       LDMIA r0!,{
    
    r4-r11}               ;从数据源取出8个字数据放到寄存器,并更新R0
       STMIA r1!,{
    
    r4-r11}               ;将数据写入目的地址,并更新R1
       SUBS  r3,r3,#1                  ;将块复制次数减1
       BNE   octcopy                   ;循环直到完成以8个字为单位的复制

        LDMFD sp!,{
    
    r4-r11}              ;恢复工作寄存器
copywords
       ANDS r2,r2,#7                   ;剩余不足8个字的数据的字数
       BEQ  stop                       ;数据复制完成则跳转到stop  
wordcopy
       LDR  r3,[r0],#4                 ;从数据源取出一个字数据到R3,并更新R0
       STR  r3,[r1],#4                 ;将字数据存储到目标地址,并更新R1
       SUBS r2,r2,#1                   ;字复制次数减1
       BNE  wordcopy                   ;循环,直到字复制完毕
                                       ;定义数据区SRC和DST
stop 
       b stop                                      
       AREA reset,DATA,READWRITE
src    DCD 1,2,3,4,5,6,7,8,8,7,6,5,4,3,2,1
       dcb "abcd1234efgh5678"
dst    DCD 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
       END

insert image description here

If you like my article, please remember to make three consecutive, like, follow, and collect. Every like, every follow, and every collection will be the infinite motivation for me to move forward! ! ! ↖(▔▽▔)↗Thanks for your support, the next issue will be more exciting! ! !

Guess you like

Origin blog.csdn.net/qq_44631615/article/details/118693259
Recommended