Chapter 4 Instruction System
Basic syntax
The assembly syntax introduced here is the syntax of the ARM assembler. If other assemblers are used, such as as in gcc, the syntax is different.
A typical pattern of assembly instructions is as follows:
Label
opcode operand1, operand2, … ;comment
The label is optional. If there is one, it must be written at the top of the page and there is no need for a ":" after the label.
The opcode is the mnemonic for the instruction and must be preceded by at least one space character.
The immediate value must start with "#", and the hexadecimal number representation method is the same as that of C language, for example:
MOV R0, #0x12 ; R0 0x12
Use the EQU directive to define constants:
NVIC_IRQ_SETEN0 EQU 0xE000E100 ; Note: constant definitions must be written at the top of the line
NVIC_IRQ0_ENABLE EQU 0x1
…
LDR R0, =NVIC_IRQ_SETEN0; Here LDR is a pseudo instruction, which will be converted by the assembler
; A "PC-relative load instruction"
MOV R1, #NVIC_IRQ0_ENABLE ; transfer the immediate value to R1
DCI can insert 1 half word (2 bytes) into the assembly code. This instruction is usually used to insert instructions that the assembler does not support.
DCB defines a string of byte constants
DCD defines a string of 32-bit integers
For example, the following example:
LDR R3, =MY_NUMBER ; R3= MY_NUMBER
LDR R4, [R3] ; R4= *R3
…
LDR R0, =HELLO_TEXT; R0= HELLO_TEXT
BL PrintText ; Call PrintText to display the string, R0 passes the parameter
…
MY_NUMBER
DCD 0x12345678
HELLO_TEXT
DCB "Hello\n",0
Instruction suffix
suffix |
meaning |
S |
Request to update the relevant flags in APSR, for example: ADDS R0, R1 ; Update the flag in APSR according to the result of addition |
EQ,NE,LT,GT, etc. |
Conditionally execute instructions. EQ=Euqal, NE= Not Equal, LT= Less Than, GT= Greater Than, for example: BEQ |
Unified Assembly Language (UAL)
Along with the Thumb-2 instruction set, a new assembly syntax (unified assembly language) also appeared. Using the syntax of the unified assembly language, we can easily choose whether the current statement is compiled into a 16-bit instruction or a 32-bit instruction.
ADD R0, R1 ; Use traditional Thumb syntax
ADD R0, R0, R1 ; Equivalent writing allowed after the introduction of UAL (R0=R0+R1)
If you use traditional Thumb syntax, some instructions will update the APSR by default.
If you use the UAL syntax, you must specify the S suffix to update. For example:
AND R0, R1 ; Traditional Thumb syntax
ANDS R0, R0, R1 ; equivalent UAL syntax (must have S suffix)
The .W (Wide) suffix specifies 32-bit instructions, and the .N suffix specifies 16-bit instructions. If no suffix is given, the assembler will first try to use 16-bit instructions to slim down the code, and if that doesn't work, it will use 32-bit instructions. For example:
ADDS R0, #1 ; The assembler will use 16-bit instructions to save space
ADDS.N R0, #1 ;Specify the use of 16-bit instructions (N = Narrow)
ADDS.W R0, #1 ;Specify the use of 32-bit instructions (W=Wide)
32-bit Thumb-2 instructions can be half-word aligned. Not having word alignment makes it easy to mix 16-bit instructions and 32-bit instructions in the code.
.
Previous article:ARM Cortex-M3 Study Notes (5)
Next article:ARM Cortex-M3 Study Notes (3)
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
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
- CGD and Qorvo to jointly revolutionize motor control solutions
- CGD and Qorvo to jointly revolutionize motor control solutions
- Keysight Technologies FieldFox handheld analyzer with VDI spread spectrum module to achieve millimeter wave analysis function
- Infineon's PASCO2V15 XENSIV PAS CO2 5V Sensor Now Available at Mouser for Accurate CO2 Level Measurement
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- A new chapter in Great Wall Motors R&D: solid-state battery technology leads the future
- Naxin Micro provides full-scenario GaN driver IC solutions
- Interpreting Huawei’s new solid-state battery patent, will it challenge CATL in 2030?
- Are pure electric/plug-in hybrid vehicles going crazy? A Chinese company has launched the world's first -40℃ dischargeable hybrid battery that is not afraid of cold
- Purgatory Legends-Character State Machine Battle
- I have seen similar block diagrams in many chip data sheets, including those of the clock RTC network. How do I understand these diagrams?
- Please recommend domestic automotive grade components
- Why can’t ping be connected?
- 【GD32450I-EVAL】Timer test ADC speed
- Common Operations of CCS Editor
- The influence of power supply on the spectrum of amplifier
- I have 4 24*18 P2.5 full-color LED dot matrix boards. Let's see what can be done? How to drive them?
- Will high voltage pulses and surges have energy and attenuation after passing through this reverse-connected diode?
- I would like to ask about the problem of low voltage detection.