Types of Instructions in Assembly Language
Assembly language serves as a bridge between high-level programming languages and machine code, in here we will take a closer look in Types of Instructions in Assembly Language.
It uses mnemonic instructions that closely resemble human-readable text to perform operations at the processor level.
In this article, we will delve into the various types of instructions in assembly language, providing explanations and examples for each category.
Understanding these instruction types is crucial for writing efficient and optimized assembly code.
Types of Instructions in Assembly Language
-
Arithmetic Instructions
Arithmetic instructions perform mathematical operations on data within registers or memory. Some common arithmetic instructions include:
- ADD: Adds two values together.
- SUB: Subtracts one value from another.
- MUL: Multiplies two values.
- DIV: Divides one value by another.
ADD R1, R2, R3 ; Adds the values in registers R2 and R3 and stores the result in R1.
SUB R1, R1, #5 ; Subtracts the immediate value 5 from the value in R1.
-
Branch Instructions
Branch instructions control the flow of execution by altering the program counter. They allow the program to jump to different locations based on certain conditions. Common branch instructions include:
- B: Unconditionally branches to a specified label or memory address.
- BEQ: Branches if the previous comparison was equal (zero flag set).
- BNE: Branches if the previous comparison was not equal (zero flag not set).
Example:
BEQ Done ; Branches to ‘Done’ if the zero flag is set (indicating equality).
-
Data Transfer Instructions
Data transfer instructions move data between registers, memory, and peripherals.
They are used to load values into registers, store values in memory, and transfer data between different locations.
Common data transfer instructions include:
- LDR: Loads a value from memory into a register.
- STR: Stores a value from a register into memory.
- MOV: Copies a value from one register to another.
Example:
STR R3, [R4] ; Stores the value in R3 into the memory address stored in R4.
MOV R5, R6 ; Copies the value from R6 into R5.
-
Logic Instructions (H2)
Logic instructions perform logical operations such as bitwise AND, OR, and NOT. These instructions manipulate individual bits within registers or memory locations.
Common logic instructions include:
- AND: Performs a bitwise AND operation between two values.
- ORR: Performs a bitwise OR operation between two values.
- EOR: Performs a bitwise XOR (exclusive OR) operation between two values.
Example:
ORR R4, R5, R6 ; Performs a bitwise OR operation between the values in R5 and R6, storing the result in R4.
-
Bit-oriented Instructions
Bit-oriented instructions allow manipulation of individual bits within a register or memory location.
They include instructions for setting, clearing, testing, and shifting bits. Common bit-oriented instructions include:
- SET: Sets a specific bit within a register.
- CLR: Clears a specific bit within a register.
- TST: Tests the value of a specific bit within a register.
Example:
CLR R2, #5 ; Clears bit 5 of R2 to 0.
TST R3, #7 ; Tests if bit 7 of R3 is set.
FAQs
Q: What are the different types of instructions in assembly language?
Q: Can you provide an example of an arithmetic instruction in assembly language?
Q: What is the purpose of bit-oriented instructions in assembly language?
Conclusion
In summary, assembly language instructions can be categorized into different types, each serving a specific purpose in low-level programming.
By understanding and utilizing these instruction types effectively, programmers can write efficient and optimized assembly code for a wide range of applications.
Whether it’s performing arithmetic operations, controlling program flow, transferring data, or manipulating bits, assembly language provides the tools necessary to interact directly with the underlying hardware.
Read more: