Embedded ARM assembly

What does assembly language look like?

  • Example: Add 100 to a value in the register.
    x86: add eax, #100
    68K: ADD #100, D0
    ARM: add r0, r0, #100

  • Example: Load from a register pointer to register
    x86: mov eax,DWORD PTR[ebx]
    68K: MOVE L (A0), D0
    ARM: ldr r0,[r1]

  • Example: ARM start code structure
    Insert picture description here

  • ARM assembly instruction format :
    Operation[cond]{status} Rd,Rn, Operand2

ARM assembly

Instruction conditions and status codes

  • Condition code (cond)
    Insert picture description here
  • Status code (Status)

Insert picture description here

ARM assembly addressing mode

  • Immediate addressing :
    ADD R0,R0,#0x3F
  • Register addressing:
    ADD R0, R1, R2
  • Register indirect addressing
    LDR R0,[R1]
    STR R0,[R1]
  • Register shift addressing
    ADD R3, R2, R1, LSL #2 (R1 is shifted two bits to the left and R1 is added, and then assigned to R3)
  • Base address addressing
    LDR R0,[R1,#4] (add the value pointed to by R1 address plus 4 to R0)
    LDR R0,[R1],#4 (add 4 to the value taken from R1 address R0)
    LDR R0,[R1,R2]
  • Multi-register addressing
    LDMIA R0,{R1,R2,R3,R4}
  • Relative addressing
    BL NEXT (jump to NEXT)
    MOV PC,LR

Data operation (ALU operation)

Insert picture description here
Insert picture description here

Logical operation (and, or, not, exclusive or)

Insert picture description here

Comparison operation

Insert picture description here

Memory operation

Single register read and write instructions,
Insert picture description here
multiple register read and write instructions
Insert picture description here

  • Address mode
    (1) Data block mode: IA (address plus 4 after transfer), IB (address plus 4 before transfer), DA (address minus 4 after transfer), DB (address minus 4 before transfer)
    (2) Stack mode: Full bottom stack, EA (empty decrement stack), FD (full decrement stack), ED (empty increment stack), FA (full increment stack)

Data exchange instructions
Insert picture description here

Jump, state operation

Opcode Operands Description Function
B Jump instruction pc<-label
BL Connection jump with return pc->-label
BX Jump and switch state Thumb
BLX Jump with return and switch state Thumb

Status register operation

Status register operation: divide 32-bit instructions into four fields: [7:0] control bit field c, [15:8] extended bit field x, [23:16] status bit field s, [31:24] condition Flag field f

Opcode Operands Description Function
MRS Transfer the value of the program status register to the general register
MSR CPSR R0 ;SPSR,R0;CPSR_c R0 General register to program status register

Exception generation instruction

Opcode Operands Description Function
SWI SWI 0x02 Soft interrupt instruction
BKPT BKPT Breakpoint interrupt instruction

ARM pseudo instructions

In the ARM assembly language program, there are some special instruction mnemonics. These mnemonics are different from the mnemonics of the instruction system. There is no corresponding operation code. These special instruction mnemonics are usually called pseudo instructions. The operation is called pseudo operation. The function of pseudo-instructions in the source program is to make various preparations for completing the assembly program. These pseudo-instructions only work in the assembly process. Once the assembly is over, the mission of the pseudo-instruction is completed.

  • Basic common pseudo instructions
    Insert picture description here
    Insert picture description here
    Insert picture description here

Symbols commonly used in assembly language programs

  • Symbol naming conventions:
    (1) Symbols are case sensitive, and uppercase and lowercase symbols with the same name will be considered by the compiler as two different symbols.
    (2) The symbol must be unique within its scope of action.
    (3) The self-defined symbols cannot be the same as the reserved words of the system.
    (4) The symbol name should not be the same as the instruction or pseudo-instruction
  • Symbols, variables
    ARM (Thumb) assembler supports numeric variables, logic variables and string variables
    Insert picture description here
  • Constant
    (1) A digital constant is generally a 32-bit integer. When used as an unsigned number, its value range is 0 ~ 232-1, when used as a signed number, its value range is -231 ~ 231-1
    ( 2) There are only two values ​​for logical constants: true or false
    (3) A string constant is a fixed string, which is generally used for information prompts when the program is running
  • Variable Substitution Character
    A variable in the program can obtain a constant through substitution operation. The substitution operator is: ""$""
    Sample:
LCLS S1
LCL S2
S1 SETS "Test!"
S2 SETS "This is a  $S1"   ;字符串变量S2的值为    This is a Test!
  • Expressions and operators
    Insert picture description here

Register operation

Register operation
Insert picture description here

Data definition pseudo assembly

Data definition pseudo assembly
Insert picture description here
Insert picture description here

Control directive

Insert picture description here
Sample:

GBLL Test ;声明一个全局的逻辑变量,变量名为Test
……
IF Test = TRUE
指令序列1
ELSE
指令序列2
ENDIF


GBLA Counter ;声明一个全局的数学变量,变量名为Counter 
Counter SETA 3 ;由变量Counter控制循环次数 
…… 
WHILE Counter < 10 
指令序列 
WEND


MACRO
$OP hello world $param1,$param2
MOV R3,#0x02
MEXIT
MEND

Guess you like

Origin blog.csdn.net/qq_41782149/article/details/96176151