Data processing instructions
Cortex-M3 supports a lot of data processing instructions. Here we will introduce the important and commonly used ones.
Four arithmetic instructions
There are four instructions for basic addition and subtraction operations, namely ADD, SUB, ADC, and SBC.
ADD Rd,Rn, Rm ; Rd = Rn+Rm
ADD Rd,Rm ; Rd += Rm
ADD Rd,#imm ; Rd += imm
ADC Rd,Rn, Rm ; Rd = Rn+Rm+C
ADC Rd,Rm ; Rd += Rm+C
ADC Rd,#imm ; Rd += imm+C
SUB Rd,Rn ; Rd -= Rn
SUB Rd,Rn, #imm3; Rd = Rn-imm3
SUB Rd,#imm8 ; Rd -= imm8
SUB Rd,Rn,Rm ; Rd = Rm-Rm
SBC Rd,Rm ; Rd -= Rm+C
SBC.W Rd,Rn, #imm12; Rd = Rn-imm12-C
SBC.W Rd,Rn, Rm; Rd = Rn-Rm-C
In addition, there is the reverse subtraction instruction RSB:
RSB.W Rd,Rn, #imm12; Rd = imm12-Rn
RSB.W Rd,Rn, Rm ; Rd = Rm-Rn
Multiplication and division instructions include MUL, UDIV/SDIV, etc.
MUL Rd,Rm ; Rd *= Rm
MUL.W Rd,Rn, Rm ; Rd = Rn*Rm
UDIV Rd,Rn, Rm ; Rd = Rn/Rm (unsigned division)
SDIV Rd,Rn, Rm ; Rd = Rn/Rm (signed division)
One instruction can perform multiplication and addition operations (usually only available in DSP):
MLA Rd, Rm, Rn, Ra; Rd = Ra+Rm*Rn
MLS Rd, Rm, Rn, Ra; Rd = Ra-Rm*Rn
It is also possible to do 32-bit by 32-bit multiplication (result is 64 bits):
SMULL RL, RH, Rm, Rn ;[RH:RL]= Rm*Rn, signed 64-bit multiplication
SMLAL RL, RH, Rm, Rn ;[RH:RL]+= Rm*Rn, signed 64-bit multiplication
UMULL RL, RH, Rm, Rn ;[RH:RL]= Rm*Rn, unsigned 64-bit multiplication
SMLAL RL, RH, Rm, Rn ;[RH:RL]+= Rm*Rn, unsigned 64-bit multiplication
Thanks to these instructions, the Cortex-M3 has considerable computing power, and the Cortex-M3 can be used to replace calculations that could only be completed with the DSP.
There are also many instructions related to logical operations, the commonly used ones include AND, ORR, BIC (bit segment clear), ORN (bitwise OR inverted), EOR (exclusive OR), LSL (logical left shift), LSR (logical right shift), ASR (arithmetic right shift), ROR (circular right shift), RRX (shift right by one bit with carry)
; Bitwise AND
AND Rd, Rn ; Rd &= Rn
AND.W Rd, Rn, #imm12 ; Rd = Rn & imm12
AND.W Rd, Rm, Rn; Rd = Rm & Rn
; Bitwise OR
ORR Rd, Rn ; Rd |= Rn
ORR.W Rd, Rn, #imm12 ; Rd = Rn | imm12
ORR.W Rd, Rm, Rn; Rd = Rm | Rn
; Clear bit by bit
BIC Rd, Rn ; Rd &= ~Rn
BIC.W Rd, Rn, #imm12; Rd = Rn & ~imm12
BIC.W Rd, Rm, Rn; Rd = Rm & ~Rn
; Bitwise OR inverse
ORN.W Rd, Rn, #imm12 ; Rd = Rn | ~imm12
ORN.W Rd, Rm, Rn; Rd = Rm | ~Rn
; Bitwise XOR
EOR Rd, Rn ; Rd ^= Rn
EOR.W Rd, Rn, #imm12; Rd = Rn ^ imm12
EOR.W Rd, Rm, Rn; Rd = Rm ^ Rn
; Logical left shift
LSL Rd, Rn, #imm5 ; Rd = Rn< LSL Rd, Rn ; Rd <<= Rn LSL.W Rd, Rm, Rn; Rd = Rm< ; Logical right shift LSR Rd, Rn, #imm5; Rd = Rn>>imm5 LSR Rd, Rn ; Rd >>= Rn LSR.W Rd, Rm, Rn; Rd = Rm>>Rn ; Arithmetic right shift ASR Rd, Rn, #imm5; Rd = Rn>> imm5 ASR Rd, Rn ; Rd =>> Rn ASR.W Rd, Rm, Rn; Rd = Rm>>Rn ; Circular right shift ROR Rd, Rn ; ROR.W Rd, Rm, Rn ; Sign-Extended Instructions SXTB Rd, Rm ; Rd = signed extension of Rm, extending the signed byte integer to 32 bits SXTH Rd, Rm ; Rd = signed extension of Rm, extending the signed half-word integer to 32 bits Byte order reversal instruction REV.W Rd, Rn; Reverse byte order within a word REV16.W Rd, Rn; Reverse byte order in high and low halfwords REVSH.W; Reverse byte order in the low halfword and do sign extension Sign-extended instructions: SXTB Rd, Rm ; Rd = sign-extended Rm SXTH Rd, Rm ; Rd = sign-extended Rm Data order reversal instruction: REV.W Rd, Rn ; Reverse byte order within a word REV16.W Rd, Rn ; Reverse byte order in high and low halfwords REVSH.W ; Reverse byte order in low halfword and sign-extend Saturation operation instructions are rarely seen in other microcontrollers. The original intention of this type of instruction is very good, but the C language does not directly support this type of operation. To use it in a C program, either inline assembly or encapsulate it into a function, which is not very convenient. This may limit the use of this type of instruction. The role of saturation operation instructions can be vividly demonstrated by the following figure: Figure 1 The function of saturation operation instruction The following are the usage of relevant instructions: SSAT.W Rd, #imm5, Rn, {,shift}; Saturate operation with signed number boundary (AC) USAT.W Rd, #imm5, Rn, {,shift}; Saturation operation at the boundary of an unsigned number (DC with ripple)Other calculation instructions
Saturation Operation
Previous article:ARM Cortex-M3 Study Notes (4-4)
Next article:ARM Cortex-M3 Study Notes (5)
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- Learn ARM development(20)
- Learn ARM development(19)
- Learn ARM development(14)
- Learn ARM development(15)
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- 【STM32WB55 Review】_02_Experience the power of ultra-low power consumption
- [Solved] How is the opencv library of dsp generated in the official data of DM8148
- Radar system basic design
- 【TI recommended course】#What is I2C design tool? #
- What is the relationship between the microcontroller baud rate, crystal oscillator and main frequency?
- Bluetooth low energy dimmable smart lighting solution
- A summary of the most downloaded electronic technical materials this week (2020.5.10~15)
- GaN Finishing Station 2
- A DCDC board, originally powered by a battery, does not work when it is powered by a switching power supply. Why?
- Lead-acid battery charging methods and conventional charging introduction