Assembly Language Instructions List
Assembly language instructions form the bridge between human-readable code and machine-executable instructions, with this simple list we will try to give you a general example.
These instructions, represented by mnemonics and operands, are vital in low-level programming.
In this article, we will delve into the world of assembly language instructions, exploring various categories such as data processing, shifting and rotating, branching operations, load and store operations, and conditionals.
Through examples, we will gain a deeper understanding of how these instructions function and their significance in programming.
Machine code refers to the binary representation of instructions that can be executed directly by a computer’s CPU.
Each assembly language instruction corresponds to a specific machine code instruction, enabling the CPU to perform the desired operations.
How to Read Assembly Instructions: Mnemonics and Operands
Assembly instructions consist of mnemonic codes, which are human-readable representations of machine code operations, and operands, which are the data or addresses on which the instructions operate.
Let’s now explore some common assembly instructions across different categories.
Instructions for Data Processing
Data processing instructions perform arithmetic and logical operations on data.
Here are some essential instructions in this category:
Syntax: ADD Rd, Rn, Operand2
Example: ADD R1, R2, #10
Adds the value 10 to the contents of register R2 and stores the result in register R1.
Syntax: SUB Rd, Rn, Operand2
Example: SUB R3, R4, R5
Subtracts the value in register R5 from the contents of register R4 and stores the result in register R3.
Compare (CMP) and Compare Negative (CMN):
Syntax: CMP Rn, Operand2
Example: CMP R6, #0
Compares the value in register R6 with 0 and updates the status flags.
Syntax: CMN Rn, Operand2
Example: CMN R7, R8
Adds the value in register R8 to the contents of register R7 and updates the status flags.
Syntax: MOV Rd, Operand2
Example: MOV R9, #25 ; Moves the value 25 into register R9
Move Negative (MVN):
Syntax: MOV Rd, Operand2
Example: MOV R9, #25
Moves the value 25 into register R9.
Bit Clear (BIC):
Syntax: MVN Rd, Operand2
Example: MVN R10, R11
Performs bitwise inversion on the contents of register R11 and stores the result in register R10.
Instructions for Shifting and Rotating
Shifting and rotating instructions manipulate the bits within registers. Here are some commonly used
instructions in this category:
Logical Shift Left (LSL):
Syntax: LSL Rd, Rm, #Shift
Example: LSL R1, R2, #2 ; Shifts the contents of R2 two positions to the left and stores the result in R1
Logical Shift Right (LSR):
Syntax: LSR Rd, Rm, #Shift
Example: LSR R3, R4, #3 ; Shifts the contents of R4 three positions to the right and stores the result in R3
Arithmetic Shift Right (ASR):
Syntax: ASR Rd, Rm, #Shift
Example: ASR R5, R6, #1 ; Shifts the contents of R6 one position to the right, preserving the sign, and
stores the result in R5
Rotate Right (ROR):
Syntax: ROR Rd, Rm, #Shift
Example: ROR R7, R8, #4 ; Rotates the contents of R8 four positions to the right and stores the result in R7
Instructions for Branching Operations
Branching instructions alter the program’s flow by directing it to different memory addresses.
Here are two commonly used branching instructions:
Syntax: B label
Example: B loop ; Branches to the label “loop” in the program
Branch Link (BL):
Syntax: BL label
Example: BL subroutine ; Branches to the subroutine specified by the label “subroutine” and saves the
return address in the link register (LR)
Instructions for Load and Store
Load and store instructions are used to transfer data between memory and registers. Here are two
Load Register (LDR):
Syntax: LDR Rd, [Rn, Offset]
Example: LDR R1, [R2, #8] ; Loads the value from memory location [R2+8] into R1
Syntax: STR Rd, [Rn, Offset]
Example: STR R3, [R4, #12] ; Stores the value in R3 into memory location [R4+12]
Load and Store Types: Byte (B), Halfword (H), Word (Omitted), Signed (SB), Unsigned (B):
These instructions allow different data types and sizes to be loaded and stored.
Instructions for Conditionals
Conditionals enable the execution of instructions based on specific conditions. Here is an example:
Conditional Execution (e.g., BEQ):
Syntax: BEQ label
Example: BEQ endloop ; Branches to the label “endloop” if the zero flag (Z) is set
Assembly language instructions serve as the fundamental building blocks of low-level programming.
Understanding their mnemonics, operands, and functionalities allows programmers to craft efficient and precise code.
By exploring data processing, shifting and rotating, branching operations, load and store operations, and conditionals, we have gained insights into various instructions and their applications.
Embracing assembly language empowers programmers to optimize code for performance and gain a deeper understanding of the underlying hardware.