Thumb pseudo-instruction
LDR (Large Range Address Read Pseudo-instruction)
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.
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 Init,Property 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.
Notice
example
1. AREA (section definition directive)
example
2. CODE16、CODE32
3. ENTRY (program entry indication pseudo-instruction)
4. END (Program end pseudo-instruction)
5. EQU (equivalent pseudo-instruction)
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.
7. IMPORT (label reference and add declaration directive)
8. Data Definition Pseudo-Operations (DCB, DCD, DCW)
assembly language programming
The steps to create an assembly language program are as follows:
example
C program to achieve the sum of 5 integers
Data block copy application example
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