ARM Cortex-M3 Study Notes (4-3)

Publisher:神秘行者Latest update time:2016-05-06 Source: eefocusKeywords:ARM  Cortex-M3 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
I'm studying ARM Cortex-M3 recently, and I found a book called "An Definitive Guide to The ARM Cortex-M3" which is considered a classic. This series of study notes is actually the reading notes I made while studying this book.

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

Other calculation instructions

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

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)

Keywords:ARM  Cortex-M3 Reference address:ARM Cortex-M3 Study Notes (4-3)

Previous article:ARM Cortex-M3 Study Notes (4-4)
Next article:ARM Cortex-M3 Study Notes (5)

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号