The most complete ARM instruction set in history

Publisher:琴弦悠扬Latest update time:2020-08-06 Source: elecfansKeywords:ARM Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Arithmetic and logical instructions

ADC : Addition with Carry

(Addition with Carry)

ADC{condition}{S} , , dest = op_1 + op_2 + carry

ADC will add two operands together and place the result in the destination register. It uses a carry flag so that additions larger than 32 bits can be made. The following example will add two 128-bit numbers.


128-bit result: Registers 0, 1, 2, and 3 First 128-bit number: Registers 4, 5, 6, and 7 Second 128-bit number: Registers 8, 9, 10, and 11


ADDS R0, R4, R8 ; add low-order word ADCS R1, R5, R9 ; add next word, with carry ADCS R2, R6, R10 ; add third word, with carry ADCS R3, R7, R11 ; add high-order word, with carry


If you are doing this addition, don't forget to set the S suffix to change the correct flag.

ADD : Addition

(Addition)

ADD{condition}{S} , , dest = op_1 + op_2

ADD will add its two operands together and place the result in the destination register. Operand 1 is a register, and operand 2 can be a register, a shifted register, or an immediate value:

ADD R0, R1, R2 ; R0 = R1 + R2 ADD R0, R1, #256 ; R0 = R1 + 256 ADD R0, R2, R3,LSL#1 ; R0 = R2 + (R3 << 1)

Addition can be performed on both signed and unsigned numbers.


AND : Logical AND

(logical AND)

AND{condition}{S} , , dest = op_1 AND op_2

AND performs a logical AND on its two operands, placing the result in the destination register; useful for masking bits you are working on. Operand 1 is a register, operand 2 can be a register, a shifted register, or an immediate value:

AND R0, R0, #3 ; R0 = Keep bits 0 and 1 of R0 and discard the rest.


Truth table for AND (if both are 1, the result is 1):

Op_1 Op_2 Result 0 0 0 0 1 0 1 0 0 1 1 1

BIC : Bit Clear

(Bit Clear)

BIC{condition}{S} , , dest = op_1 AND (!op_2)

BIC is a method of clearing bits in a word, the opposite of OR bit setting. Operand 2 is a 32-bit bit mask. If a bit in the mask is set, it is cleared. Unset mask bits indicate that the bit remains unchanged.


BIC R0, R0, #%1011 ; Clear bits 0, 1, and 3 in R0. Leave the rest unchanged.

BIC truth table:

Op_1 Op_2 Result 0 0 0 0 1 0 1 0 1 1 1 0

Note: The logical expression is Op_1 AND NOT Op_2

EOR : Logical exclusive OR

(logical Exclusive OR)

EOR{condition}{S} , , dest = op_1 EOR op_2

EOR performs a logical exclusive OR on the two operands, placing the result in the destination register; useful for inverting specific bits. Operand 1 is a register, operand 2 can be a register, a shifted register, or an immediate value:

EOR R0, R0, #3 ; Invert bits 0 and 1 in R0

EOR truth table (the result is 1 if the two are different):

Op_1 Op_2 Result 0 0 0 0 1 1 1 0 1 1 1 0

MOV : Transfer

(Move)

MOV{condition}{S} , dest = op_1

MOV loads a value from another register, a shifted register, or an immediate value into a destination register. You can specify the same register to achieve the effect of a NOP instruction, and you can also specifically shift a register:

MOV R0, R0 ; R0 = R0... NOP instruction MOV R0, R0, LSL#3 ; R0 = R0 * 8

If R15 is the destination register, the program counter or flags will be modified. This is used to return to the calling code by transferring the contents of the link register to R15:

MOV PC, R14 ; exit to caller MOVS PC, R14 ; exit to caller and restore flags (not compliant with 32-bit architecture)

MVN : Transmit the negated value

(MoveNegative)

MVN{condition}{S} , dest = !op_1

MVN loads a value from another register, a shifted register, or an immediate value into a destination register. The difference is that the bits are inverted before the transfer, so a negated value is transferred to a register. This is a logical NOT operation rather than an arithmetic operation, and the negated value plus 1 is its negation:

MVN R0, #4 ; R0 = -5 MVN R0, #0 ; R0 = -1

ORR : Logical OR

(logical OR)

ORR{condition}{S} , , dest = op_1 OR op_2

OR performs a logical OR on the two operands, placing the result in the destination register; useful for setting specific bits. Operand 1 is a register, operand 2 can be a register, a shifted register, or an immediate value:

ORR R0, R0, #3 ; Set bits 0 and 1 in R0

OR truth table (if 1 exists in either value, the result is 1):

Op_1 Op_2 Result 0 0 0 0 1 1 1 0 1 1 1 1

RS B : Reverse subtraction

(Reverse Subtraction)

RSB{condition}{S} , , dest = op_2 - op_1

SUB subtracts operand one from operand two, placing the result in the destination register. Operand 1 is a register, and operand 2 can be a register, a shifted register, or an immediate value:

RSB R0, R1, R2 ; R0 = R2 - R1 RSB R0, R1, #256 ; R0 = 256 - R1 RSB R0, R2, R3,LSL#1 ; R0 = (R3 << 1) - R2

Inverse subtraction can be performed on signed or unsigned numbers.

RSC : Reverse Subtraction with Borrow

(Reverse Subtraction with Carry)

RSC{condition}{S} , , dest = op_2 - op_1 - !carry

Same as SBC, but with the operands swapped.

SBC : Subtraction with Borrow

(Subtraction with Carry)

SBC{condition}{S} , , dest = op_1 - op_2 - !carry

SBC subtracts the two operands and places the result in the destination register. It uses the carry flag to indicate a borrow, so that it can do subtractions greater than 32 bits. SUB and SBC generate the carry flag differently than the normal way, clearing the carry flag if a borrow is required. Therefore, the instruction performs a negation on the carry flag - the bit is automatically inverted during the execution of the instruction.

SUB : Subtraction

(Subtraction)

SUB{condition}{S} , , dest = op_1 - op_2

SUB subtracts operand two from operand one and places the result in the destination register. Operand 1 is a register and operand 2 can be a register, a shifted register, or an immediate value:

SUB R0, R1, R2 ; R0 = R1 - R2 SUB R0, R1, #256 ; R0 = R1 - 256 SUB R0, R2, R3,LSL#1 ; R0 = R2 - (R3 << 1)

Subtraction can be performed on both signed and unsigned numbers.

Shift Instructions

The ARM processor has a barrel shifter that  can be used with data processing instructions (ADC, ADD, AND, BIC, CMN, CMP, EOR, MOV, MVN, ORR, RSB, SBC, SUB, TE Q, TST ) . You can also use the barrel shifter to affect the index value in LDR/STR operations.

Annotation: Shift operations are not used as separate instructions in the ARM instruction set. They are a field in the instruction format and are represented as options in the instruction in assembly language. If the second operand of a data processing instruction or the index in a single data transfer instruction is a register, various shift operations can be performed on it. If the second operand of a data processing instruction is an immediate value, it is represented in the instruction using an 8-bit immediate value and a 4-bit rotation. So for an immediate value greater than 255, the assembler tries to represent it by setting the rotation amount in the instruction, and generates an error if it cannot be represented. In logic class instructions, logical operation instructions determine whether the carry flag is affected by setting or clearing the S bit in the instruction, while the S bit of the comparison instruction is always set. The amount of shift can only be specified using an immediate value and not a register in a single data transfer instruction.


Here are six mnemonics for the different shift types:

LSL Logical Shift Left ASL Arithmetic Shift Left LSR Logical Shift Right ASR Arithmetic Shift Right ROR Rotate Right RRX Rotate Right with Extend


ASL and LSL are equivalent and can be used freely interchangeably.

You can specify the shift amount as an immediate value (from 0 to 31), or as a register containing a value between 0 and 31.


Logical or arithmetic left shift

(Logical or Arithmetic Shift Left)

Rx, LSL #n or Rx, ASL #n or Rx, LSL Rn or Rx, ASL Rn

Takes the contents of Rx and shifts them in the MSB direction by the amount specified by 'n' or in register Rn. The least significant bits are filled with zeros. The leftmost MSB is discarded except for the conceptual 33rd bit (which is the smallest bit shifted out). If the S bit is set in the logical instruction, this bit becomes the value of the carry flag on exit from the barrel shifter.


Consider the following:

MOV R1, #12 MOV R0, R1, LSL#2

On exit, R0 is 48. The sum formed by these instructions is R0 = #12, LSL#2 which is equivalent to B ASIC  's R0 = 12 << 2


Logical right shift

(Logical Shift Right)

Rx, LSR #n or Rx, LSR Rn

It is conceptually the opposite of left shift. It shifts all bits towards the less significant bits. If the S bit is set in the logic instruction, the last bit shifted out of the rightmost position is placed in the carry flag. It is the same as register = value >>> shift in BASIC.


Arithmetic right shift

(Arithmetic Shift Right)

Rx, ASR #n or Rx, ASR Rn

Similar to LSR, but uses the value of bit 31 of the register to be shifted (Rx) to fill the high bits, to preserve the sign in the two's complement representation. If the S bit is set in the logic instruction, the last bit shifted out of the rightmost position is placed in the carry flag. This is the same as register = value >> shift in BASIC.


Circular right shift

(Rotate Right)

Rx, ROR #n or Rx, ROR Rn

A circular right shift is similar to a logical right shift, but places the bits shifted out of the right side on the left side, and if the S bit is set in the logical instruction, places them in the carry flag, which is a 'loop' of the bits. A shift by 32 will result in an output that is exactly the same as the input, because all the bits have been shifted 32 places back to where they started!


Rotate right with extension

(Rotate Right with extend)

Rx, RRX

This is a ROR#0 operation, which shifts right one position - the difference is that it uses the processor's carry flag to provide a 33-bit amount to be shifted.


Multiplication Instructions

Instruction format:

These two instructions differ from ordinary arithmetic instructions in the restrictions on operands:

All operands and destination registers given must be simple registers.

You cannot use an immediate value or a shifted register for operand 2.

The destination register and operand 1 must be different registers.

Finally, you cannot specify R15 as the destination register.

[1] [2] [3]
Keywords:ARM Reference address:The most complete ARM instruction set in history

Previous article:Overall Architecture Design of Embedded Firewall Based on ARM Processor
Next article:Brief Analysis of Intelligent Lighting Control System Based on ARM

Recommended ReadingLatest update time:2024-11-17 08:37

ARM instruction classification (details)
instruction: Data processing instructions can only operate on register contents, not memory contents. All data processing instructions can use the suffix s to affect the flag bits Data processing instructions Data transfer instructions Arithmetic and logical operation instructions Comparison Instructions Jump Inst
[Microcontroller]
ARM instruction classification (details)
Design of Multi-channel Data Acquisition System Based on ARM Cortex-M3
0 Introduction The data acquisition system converts the analog signals such as temperature, pressure, flow, displacement, etc. output by the acquisition sensor into digital signals that can be recognized by the computer, and performs corresponding calculations, storage and processing; at the same time, the calcu
[Microcontroller]
Design of Multi-channel Data Acquisition System Based on ARM Cortex-M3
Design of portable power quality analyzer based on DSP+ARM
0 Introduction With the expansion of national industrial scale and the development of science and technology, the load structure of power grid has changed greatly. On the one hand, the massive growth of nonlinear, impact and unbalanced loads has deteriorated the power quality; on the other hand, with the develop
[Microcontroller]
Design of portable power quality analyzer based on DSP+ARM
Design of digital microwave monitoring system based on ARM chip LPC2214 and μC/OS-II
With the popularization and deepening of embedded system development, traditional software development methods are difficult to meet the needs of more complex applications. Embedded operating systems play an increasingly important role in development and have been widely used in mobile phones and mobile computers. Equ
[Microcontroller]
Design of digital microwave monitoring system based on ARM chip LPC2214 and μC/OS-II
【ARM】Use J-Link to download u-boot to Mini2440 development board
#1 Introduction to various guide systems ##1.1 bios 1 BIOS is the abbreviation of "Basic Input Output System". In fact, it is a set of programs fixed on a ROM chip on the motherboard of the computer. It stores the most important basic input and output programs of the computer, system setting information, self-test pro
[Microcontroller]
【ARM】Use J-Link to download u-boot to Mini2440 development board
ARM Study Notes 11——GNU ARM Assembly Programming
  In GNU ARM assembly programming, the syntax format of each line is as follows:    @comment    If the statement is too long, you can write it in several lines, and use "" at the end of the line to indicate a line break. There cannot be any characters after "", including spaces and tabs.   Parameter description:
[Microcontroller]
A Design Scheme of Audio Processing System Based on ARM+DSP
With the rapid development of computer technology, electronic technology and communication technology, audio processing technology has also been widely used in many fields, such as mobile phones and IP phones in the communication field, MP3 and CD players in consumer electronics, and speech recognition and voice contr
[Embedded]
A Design Scheme of Audio Processing System Based on ARM+DSP
ARM11 S3C6410 address table
Reference: 1) "ARM1176 JZF-S Technical Reference Manual": Chapter 3 System Control Coprocessor Chapter 6 Memory Management Unit 2) u-boot source code: u-boot-xxx/cpu/s3c64xx/start.S u-boot-xxx/board/samsung/smdk6410/lowlevel_init.S 1. Brief description of ARMv6 MMU 1) MMU is controlled by coprocessor CP15; 2) MMU func
[Microcontroller]
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号