ARM汇编语言程序设计总结

发布时间 : 星期二 文章ARM汇编语言程序设计总结更新完毕开始阅读

ARM汇编语言程序设计总结

一、常用指令

1.存储器访问指令

LDR STR

LDR

Load 32-bit word to Memory. Syntax

LDR{cond} Rd, [Rn]

LDR{cond} Rd, [Rn, offset] LDR{cond} Rd, [Rn, offset]! LDR{cond} Rd, label LDR{cond} Rd, [Rn], offset Description

LDR{cond} Rd, [Rn, offset] (Pre-indexed offset) Rn and offset are added and used as address value.

LDR{cond} Rd, [Rn, offset]{!} (Pre-indexed offset with update)

Rn and offset are added and used as address value. The new address value is written to Rn. LDR{cond} Rd, label (Program-relative)

The assembler calculates the PC offset and generates LDR{cond} Rd, [R15, offset]. LDR{cond} Rd, [Rn], offset (Post-indexed offset)

Rn is used as address value. After memory transfer, the offset is added to Rn. Example

LDR{cond} Rd, [Rn] (zero offset)

Rn is used as address value.

LDR R8,[R10] //loads r8 from the address in r10. LDRNE R2,[R5,#960]! //(conditionally) loads r2 from a word 960 bytes above the address in r5, and increments r5 by 960.

LDR R0,localdata //loads a word located at label localdata

STR

Store register 32-bit words to Memory. The address must be 32-bit word-aligned.

Syntax STR{cond} Rd, [Rn]

STR{cond} Rd, [Rn, offset] STR{cond} Rd, [Rn, offset]! STR{cond} Rd, label

STR{cond} Rd, [Rn], offset Description

STR{cond} Rd, [Rn] (zero offset)

Rn is used as address value.

STR{cond} Rd, [Rn, offset] (Pre-indexed offset) Rn and offset are added and used as address value.

STR{cond} Rd, [Rn, offset]! (Pre-indexed offset with update)

Rn and offset are added and used as address value. The new address value is written to Rn. STR{cond} Rd, label (Program-relative)

The assembler calculates the PC offset and generates STR{cond} Rd, [R15], offset. STR{cond} Rd, [Rn], offset (Post-indexed offset)

Rn is used as address value. After memory transfer, the offset is added to Rn. Example

LDR r8,[r10] //loads r8 from the address in r10.

LDRNE r2,[r5,#960]! //(conditionally) loads r2 from a word //960 bytes above the address in r5, and //increments r5 by 960.

STR r2,[r9,#consta-struc] //consta-struc is an expression evaluating

//to a constant in the range 0-4095. STRB r0,[r3,-r8,ASR #2] //stores the least significant byte from

//r0 to a byte at an address equal to //contents(r3) minus contents(r9)/4. //r3 and r8 are not altered.

STR r5,[r7],#-8 //stores a word from r5 to the address //in r7, and then decrements r7 by 8. LDR r0,localdata //loads a word located at label localdata

2.一般数据处理指令

ADD SUB ADC SBC

AND, ORR, EOR, CMP TST

UMULL, UMLAL, SMULL, and SMLAL MUL, MLA, and MLS

ADC

Add with Carry. Syntax Description

ADC{cond}{S} Rd, Rn, Op2

Add Rn and Op2 and Carry flag and store result to Rd. ADC is typical used

for multi-word arithmetic.

Condition Flags If S is specified update flags: N, Z, C, V. Example

ADDS R0,R2,R4 // add R2 + R4, store result to R0, set flags

ADC R1,R3,R5 // add R3 + R5 with carry from previous ADDS, store result to R1

ADD

Add values and store result to register. Syntax Description Example

ADD{cond}{S} Rd, Rn, Op2

Add Rn and Op2 and store result to Rd.

Condition Flags If S is specified update flags: N, Z, C, V.

ADDS R0,R2,R4 //Add R2 and R4 and store result to R0, update flags

ADD R4,R4,#0xFF00 //Add value in 0xFF00 and R4 and store result in R4

SUB

Subtract registers. Syntax Description Condition Flags Example

SUB{cond}{S} Rd, Rn, Op2

subtracts the value of Op2 from the value in Rn. If S is specified update flags: N, Z, C, V.

SUBS R8,R6,#240 //R8=R6-240

SBC

Subtract with carry. Syntax Description Condition Flags Example

SBC{cond}{S} Rd, Rn, Op2 synthesize multiword arithmetic. If S is specified update flags: N, Z, C, V.

ADDS R0,R2,R4

ADD R4,R4,#0xFF00

AND

Logical AND operation. Syntax Description

AND{cond}{S} Rd, Rn, Op2

Load Rd with logical AND of Rn with Op2. Rd := Rn AND Op2

Condition Flags If S is specified, N, Z flags are updated. C flag may be updated by calculation of Op2. Example

AND R9,R2,#0xFF00 // Load R9 with R2 and value in 0xFF00

ORR

Logical OR operation. Syntax Description

ORR{cond}{S} Rd, Rn, Op2

OR operations on the values in Rn and Op2.

Condition Flags If S is specified, N, Z flags are updated. C flag may be updated by calculation of Op2. Example

ORR R2, R0, R5 // Rd = R0 or R5

CMP

Compare. Used in combination with conditional branch instructions. Syntax Description

CMP {cond} Rn, Op2

subtracts the value of Op2 from the value in Rn (equals to the SUBS

instruction with a discarded result).

This instruction updates the condition flags, but do not place a result in a register. Condition Flags N, Z, C and V flags are updated. Example

CMP R2, R9 //Subtract value of R9 from R2

TST

Test.

联系合同范文客服:xxxxx#qq.com(#替换为@)