7 Introduction To Assembly Language
7 Introduction To Assembly Language
Assembly language is a low-level programming language that is closely related to machine code,
the native language of a computer's central processing unit (CPU). Unlike high-level languages
(such as Python or Java), which abstract away the hardware details, assembly language provides a
direct interface to the hardware, offering fine-grained control over the CPU's operations. It is used
primarily in systems programming, embedded systems, and performance-critical applications
where understanding and manipulating the hardware is essential.
Basic Syntax
Assembly language syntax can vary between different processors and assemblers, but the basic
structure includes the following elements:
• Labels: Used to identify a location in code.
• Instructions: The operation to be performed.
• Operands: The data or addresses the instruction will operate on.
• Directives: Commands to the assembler that are not translated into machine code but affect
the assembly process.
Example Program
Here's a simple assembly program that demonstrates some of these instructions. This program adds
two numbers and stores the result.
Understanding the Example
1. Data Section:
• section .data is where we define variables. num1, num2, and result are defined
here.
2. Text Section:
• section .text contains the code.
• global _start makes _start the entry point.
• _start: is a label marking the beginning of the program.
3. Instructions:
• mov al, [num1] loads the value of num1 into register AL.
• add al, [num2] adds the value of num2 to AL.
• mov [result], al stores the result in result.
• The final three instructions (mov eax, 60, xor edi, edi, syscall) are used to exit the
program.