Cortex-M0/M0+指令集

本文详细介绍了ARMv6-M架构中用于Cortex-M0和Cortex-M0+处理器的指令集特性,包括数据移动、内存访问、算术运算等基本指令,以及条件分支、内存屏障等高级指令,并探讨了这些指令如何帮助实现高效可靠的嵌入式系统。
摘要由CSDN通过智能技术生成

For the ARMv6-M architecture used in the Cortex-M0 and Cortex-M0+ Processors, in order to reduce the circuit size to a minimum, only the 16-bit Thumb instructions and a minimum subset of 32-bit Thumb instructions(BL, MSR, MRS, DMB, DSB, ISB) are supported.

Moving Data within the Processor

MOV  <Rd>, <Rm> // Rm and Rn can be high or low registers.
MOVS <Rd>, <Rm>
MOVS <Rd>, #immed8
MRS  <Rd>, <SpecialReg>
MSR  <SpecialReg>, <Rd>

Memory Accesses

It is important to make sure the memory address accessed is aligned.Unaligned transfers are not supported on the ARMv6-M Architecture (include Cortex-M0 and Cortex-M0 processors). Any attempt at unaligned memory access result in a HardFault exception.

LDR  <Rt>,[<Rn>, <Rm>]    // Rt = memory[Rn + Rm]
STR  <Rt>,[<Rn>, <Rm>]    // memory[Rn + Rm] = Rt
LDRH <Rt>,[<Rn>, <Rm>]    // Rt = memory[Rn + Rm]
STRH <Rt>,[<Rn>, <Rm>]    // memory[Rn + Rm] = Rt
LDRB <Rt>,[<Rn>, <Rm>]    // Rt = memory[Rn + Rm]
STRB <Rt>,[<Rn>, <Rm>]    // memory[Rn + Rm] = Rt
LDRSH <Rt>,[<Rn>, <Rm>]   // Rt = SignExtend(memory[Rn + Rm])
LDRSB <Rt>,[<Rn>, <Rm>]   // Rt = SignExtend(memory[Rn + Rm])
LDR  <Rt>,[<Rn>, #immed5] // Rt = memory[Rn + ZeroExtend (#immed5<<2)]
STR  <Rt>,[<Rn>, #immed5] // memory[Rn + ZeroExtend(#immed5<<2)] = Rt
LDRH <Rt>,[<Rn>, #immed5] // Rt = memory[Rn + ZeroExtend (#immed5<<1)]
STRH <Rt>,[<Rn>, #immed5] // memory[Rn + ZeroExtend(#immed5<<1)] = Rt
LDRB <Rt>,[<Rn>, #immed5] // Rt = memory[Rn + ZeroExtend (#immed5)]
STRB <Rt>,[<Rn>, #immed5] // memory[Rn + ZeroExtend(#immed5)] = Rt
LDR  <Rt>,[SP, #immed8]   // Rt = memory[SP + ZeroExtend(#immed8<<2)]
STR  <Rt>,[SP, #immed8]   // memory[SP + ZeroExtend(#immed8<<2)] = Rt
LDR  <Rt>,[PC, #immed8]   // Rt = memory[WordAligned(PC + 4) + ZeroExtend(#immed8<<2)]
LDR  <Rd>, =immed32       // pseudo instruction translated to LDR <Rt>,[PC, #immed8]
LDR  <Rd>, label          // pseudo instruction translated to LDR <Rt>,[PC, #immed8]
LDM <Rn>,{<Ra>, <Rb>,..} // Load Multiple
// Ra = memory[Rn]
// Rb = memory[Rn + 4],
// ...
LDMIA <Rn>!, {<Ra>, <Rb>,..} // Load Multiple Increment After
LDMFD <Rn>!, {<Ra>, <Rb>,..}
// Ra = memory[Rn],
// Rb = memory[Rn + 4],
// ...
// and then update Rn to last read address plus 4.

STMIA <Rn>!, {<Ra>, <Rb>,..} // Store Multiple Increment After
STMEA <Rn>!, {<Ra>, <Rb>,..}
// memory[Rn] = Ra,
// memory[Rn + 4] = Rb,
// ...
// and then update Rn to last store address plus 4.

Stack Memory Accesses

PUSH {<Ra>, <Rb>, ..}
PUSH {<Ra>, <Rb>, .., LR}
POP  {<Ra>, <Rb>, ..}
POP  {<Ra>, <Rb>, .., PC}

Arithmetic Operations

ADD  <Rd>, <Rm>          // Rd = Rd + Rm. Rd, Rm can be high or low registers.
ADDS <Rd>, <Rn>, <Rm>    // Rd = Rn + Rm
SUBS <Rd>, <Rn>, <Rm>    // Rd = Rn – Rm
ADDS <Rd>, <Rn>, #immed3 // Rd = Rn + ZeroExtend(#immed3)
SUBS <Rd>, <Rn>, #immed3 // Rd = Rn – ZeroExtend(#immed3)
ADDS <Rd>, #immed8       // Rd = Rd + ZeroExtend(#immed8)
SUBS <Rd>, #immed8       // Rd = Rd – ZeroExtend(#immed8)
ADCS <Rd>, <Rd>, <Rm>    // Rd = Rd + Rm + Carry
SBCS <Rd>, <Rd>, <Rm>    // Rd = Rd – Rm – Borrow
ADD  SP, SP, #immed7     // SP = SP + ZeroExtend(#immed7<<2)
SUB  SP, SP, #immed7     // SP = SP – ZeroExtend(#immed7<<2)
ADD  SP, <Rm>            // SP = SP + Rm. Rm can be high or low register.
ADD  <Rd>, SP, <Rd>      // Rd = Rd + SP. Rd can be high or low register.
ADD  <Rd>, SP, #immed8   // Rd = SP + ZeroExtend(#immed8<<2)
ADD  <Rd>, PC, #immed8   // Rd = (PC[31:2]<<2) + ZeroExtend(#immed8<<2)
ADR  <Rd>, <label>       // pseudo instruction translated to ADD <Rd>, PC, #immed8
RSBS <Rd>, <Rn>,#0       // Rd = 0 – Rm, Reverse Subtract (negative)
MULS <Rd>, <Rm>, <Rd>    // Rd = Rd * Rm
CMP <Rn>, #immed8        // Rd – ZeroExtended(#immed8)
CMP <Rn>, <Rm>           // Rn – Rm
CMN <Rn>, <Rm>           // Rn – NEG(Rm)

Logic Operations

ANDS <Rd>, <Rd>, <Rm> // Rd = AND(Rd, Rm)
ORRS <Rd>, <Rd>, <Rm> // Rd = OR(Rd, Rm)
EORS <Rd>, <Rd>, <Rm> // Rd = XOR(Rd, Rm)
BICS <Rd>, <Rd>, <Rm> // Rd = AND(Rd, NOT(Rm))
MVNS <Rd>, <Rm>       // Rd = NOT(Rm)
TST  <Rn>, <Rm>       // AND(Rn, Rm)

Shift and Rotate Operations

ASRS <Rd>, <Rm>, #immed5 // Rd = Rm>>immed5
LSLS <Rd>, <Rm>, #immed5 // Rd = Rm<<#immed5
LSRS <Rd>, <Rm>, #immed5 // Rd = Rm>>#immed5
ASRS <Rd>, <Rd>, <Rm>    // Rd = Rd>>Rm
LSLS <Rd>, <Rd>, <Rm>    // Rd = Rd<<Rm
LSRS <Rd>, <Rd>, <Rm>    // Rd = Rd>>Rm
RORS <Rd>, <Rd>, <Rm>    // Rd = Rd rotate right by Rm bits
// Rotate_Left(Data, offset) = Rotate_Right(Data, (32-offset))

Reverse Ordering Operations

These reverse instructions are usually used for converting data between little endian and
big endian systems.

REV <Rd>, <Rm> // Byte-Reverse Word
// Rd = {Rm[7:0], Rm[15:8], Rm[23:16], Rm[31:24]}

REV16 <Rd>, <Rm> // Byte-Reverse Packed Half Word
// Rd = {Rm[23:16], Rm[31:24], Rm[7:0] , Rm[15:8]}

REVSH <Rd>, <Rm> // Byte-Reverse Signed Half Word
// Rd = SignExtend({Rm[7:0] , Rm[15:8]})

Extend Operations

They are usually used for data type conversions.

SXTB <Rd>, <Rm> // Signed Extended Byte
// Rd = SignExtend(Rm[7:0])

SXTH <Rd>, <Rm> // Signed Extended Half Word
// Rd = SignExtend(Rm[15:0])

UXTB <Rd>, <Rm> // Unsigned Extended Byte
// Rd = ZeroExtend(Rm[7:0])

UXTH <Rd>, <Rm> // Unsigned Extended Half Word
// Rd = ZeroExtend(Rm[15:0])

Program Flow Control

B <label>       // Branch, Branch range is ±2046 bytes of current PC
B<cond> <label> // Conditional Branch, Branch range is ±254 bytes of current PC
BL <label>      // Branch and Link, Branch range is ±16 MB of current PC
BX <Rm>         // Branch and Exchange
BLX <Rm>        // Branch and Link with Exchange

Conditional branch instructions B

Required branch controlUnsigned dataSigned data
If (R0 equal R1) then branchBEQ labelBEQ label
If (R0 not equal R1) then branchBNE labelBNE label
If (R0 > R1) then branchBHI labelBGT label
If (R0 >= R1) then branchBCS label/BHS labelBGE label
If (R0 < R1) then branchBCC label/BLO labelBLT label
If (R0 <= R1) then branchBLS labelBLE label
If (overflow(R0 + R1)) then branchBCS labelBVS label
If (no_overflow(R0 + R1)) then branchBCC labelBVC label
If (overflow(R0 – R1)) then branchBCC labelBVS label
If (no_overflow(R0 – R1)) then branchBCS labelBVC label
If (result >= 0) then branchNot applicableBPL label
If (result < 0) then branchNot applicableBMI label

Memory Barrier Instructions

The memory barrier instructions are supported on the Cortex-M0 and Cortex-M0 processors to provide better compatibility within the Cortex-M processors and other ARM processor families.


// Data Memory Barrier, Ensures that all memory accesses are completed 
// before new memory access is committed.
DMB

// Data Synchronization Barrier, Ensures that all memory accesses are completed 
// before next instruction is executed.
DSB

// Instruction Synchronization Barrier, Flushes the pipeline and 
// ensure that all previous instructions are completed 
// before executing new instructions.
ISB

Exception-Related Instructions

SVC <immed8> // Supervisor call
CPSIE I      // Enable Interrupt (Clearing PRIMASK)
CPSID I      // Disable Interrupt (Setting PRIMASK)

Sleep Mode Feature-Related Instructions

// Wait For Interrupt, Stops program execution until an interrupt arrived,
// or if the processor entered a debug state.
WFI

// Wait For Event, If the internal event register is set, it clears the
// internal event register and continues execution.
// Otherwise stop program execution until an event (e.g., an interrupt) arrive, 
// or if the processor enters debug state.
WFE

// Send Event, Set local event register and send out an event pulse to
// other microprocessor in a multiple processor system.
SEV

Other Instructions

NOP           // No Operation
BKPT <immed8> // Break point
YIELD         // Execute as NOP on the Cortex-M0 processor
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值