ARM Assembly Language - Introduction [Part 2]

Publisher:MagicalSerenadeLatest update time:2021-06-15 Source: eefocusKeywords:ARM Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

The above article introduces ARM's data transfer instructions. This article will mainly introduce ARM's data processing instructions such as shift, sequence rotation and bit operation.


【Shift instruction】


Shifting includes logical shift and arithmetic shift. The so-called "logical" means that the content stored in the register is just regarded as a string of bits. When shifting, you only need to shift these bits directly to the left (LSL - Logical Shift Left) or right (LSR - Logical Shift Righ). Because the bit width of the register is fixed, some bits will be shifted out of the register.

If you use a circular logical shift instruction such as ROR (Rotate Right), the bits shifted out of the LSB will be moved to the MSB in sequence. Since LSR has a corresponding LSL, does ROR also have a corresponding ROL (Rotate Left)? No, taking a 32-bit system as an example, the effect of circularly shifting left by n bits and circularly shifting right by 32-n bits is actually the same.

Arithmetic, on the other hand, treats the contents of a register as a value, and when shifting, the positive and negative values ​​need to be considered. In ARM, there is only an arithmetic shift right (ASR) instruction, but no arithmetic shift left instruction. In an arithmetic shift right, the vacant bit at the MSB end will be filled with the MSB representing the sign, and each right shift by one bit is equivalent to dividing by 2.

[Data sequence transfer instruction]


"Data reordering" refers to partially swapping bits or bytes in a register. There are many forms of reordering, including the RBIT instruction that reverses all bits, the REV instruction that reverses all bytes, and the REV16 instruction that reverses bytes in two 16-bit half words.

Among them, the REV instruction is probably the most used, because it can be used to convert between Little-Endian (LE) and Big-Endian (BE) in network transmission. In ARMv8, data access can be LE or BE according to the setting of the system control register SCTLR, but instruction fetch is always LE.

On 64-bit systems, a REV32 instruction is added to reverse the bytes in two 32-bit words:

【Bit's Scalpel】


Traditional bit operation instructions such as AND and ORR are frequently used and easy to understand, but if you want to implement some more complex bit operations, you need some more professional instructions, such as the BFI (Bit Field Insert) instruction to insert part of the bits of a register into the specified part of another register, or the BFX (Bit Field Extract) instruction to directly extract these bits, and the BFC (Bit Field Clear) instruction to clear the bits of a specified part.


For example, "BFI W0, W1, #9, #6" means inserting the 6 bits at the LSB end of the W1 register into the W0 register from bit 9 to bit 14.

As I write this, I think of gene editing, and I recommend everyone to read Professor Wang Liming’s "God's Scalpel".


The following will introduce the unconditional jump instructions and conditional jump instructions in ARM.


Keywords:ARM Reference address:ARM Assembly Language - Introduction [Part 2]

Previous article:ARM Assembly Language - Introduction [Part 3]
Next article:ARM Assembly Language - Introduction [I]

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号