Assembly Language - Introduction
Assembly Language is the layer closest to hardware in the family of computer programming languages; it is a human-readable mnemonic representation of machine instructions.
Understanding the essence of assembly language is the first step to deeply learning computer systems.
What is Assembly Language
A computer's CPU can only understand and execute0s and 1sthat make up binary machine code.
For example, in the x86 architecture, the machine codeB8 2A 00 00 00represents moving the value 42 into the EAX register.
Writing binary machine code directly is extremely difficult and error-prone for humans, so assembly language came into being.
Assembly language uses human-readablemnemonics (Mnemonic)to represent these binary instructions. For example, the machine code above is written in assembly as:
Example
An assembler is responsible for translating these mnemonics back into machine code that the CPU can execute.
In the example above,movis the mnemonic,eaxis the destination operand,42is the source operand.
Assembly language uses mnemonics to replace machine language operations, supports labels and symbols to refer to addresses and constants, avoiding hardcoding. Assembly language corresponds roughly one-to-one with the corresponding machine language instruction set.

Relationship between Assembly Language and Machine Code
Between assembly instructions and machine instructions, there isa one-to-one correspondencerelationship.
Each assembly instruction precisely maps to one CPU machine instruction, with no intermediate abstraction layer.
| Form | Example | Description |
|---|---|---|
| Machine code (binary) | 10111000 00101010 00000000 00000000 00000000 | Instructions directly executed by the CPU |
| Machine code (hexadecimal) | B8 2A 00 00 00 | Human-readable machine code representation |
| Assembly language | mov eax, 42 | Human-readable mnemonic representation |
Assembly language and machine code have a one-to-one correspondence, but CPUs of different architectures have different instruction sets. For example, the assembly syntax of x86 and ARM is completely different.
Differences between Assembly and High-Level Languages
The following figure shows the different paths from source code to execution for high-level languages and assembly language:
| Feature | Assembly language | High-level language (e.g., Python) |
|---|---|---|
| Abstraction level | Lowest level, directly manipulates hardware | High-level, operating system and runtime encapsulate details |
| Code size | Simple functions require a lot of code | A small amount of code implements complex functions |
| Readability | Difficult to read and maintain | Human-friendly, easy to understand |
| Execution efficiency | Highest, no runtime overhead | Lower, has interpretation or compilation overhead |
| Hardware control | Full control over CPU and memory | Indirect access through abstract interfaces |
| Portability | Poor, needs rewriting for different CPUs | Good, the same code can run on multiple platforms |
Application Scenarios of Assembly Language
Although assembly language is not a mainstream choice for daily development, it is still irreplaceable in specific fields:
| Field | Specific application |
|---|---|
| Operating system kernel | Bootloader, context switching, interrupt handling, etc. must be written in assembly |
| Embedded systems | Devices with extremely limited resources require precise hardware control |
| Reverse engineering | Analyzing malware, cracking software protection, understanding closed-source program logic |
| Performance-sensitive code | Core functions with extremely high performance requirements, such as encryption algorithms and audio/video codecs |
| Security research | Writing shellcode, exploit code |
| Compiler development | Understanding target code generation, writing or optimizing compiler backends |
Introduction to x86 Architecture
x86It is a microprocessor architecture introduced by Intel, starting with the 8086 processor in 1978, and going through generations such as 80286, 80386 (i386), 80486, Pentium, etc.
x86 is the most widely used desktop and server CPU architecture, and an ideal platform for learning assembly language.
This tutorial uses32-bit x86 architecture(also called IA-32 or i386) as the teaching foundation, because its register model is concise and clear, suitable for beginners.
32-bit x86 assembly is the best starting point for learning assembly language. After mastering 32-bit, transitioning to 64-bit (x86-64) is very natural, because the latter is an extension of the former.
Introduction to NASM Assembler
NASM(Netwide Assembler)It is an open-source x86 assembler that supports multiple output formats and all major operating systems.
Compared to MASM (Microsoft Assembler) and GAS (GNU Assembler), NASM's syntax is clearer and more intuitive, making it the best choice for learning assembly language.
| Assembler | Syntax style | Platform | Features |
|---|---|---|---|
| NASM | Intel syntax | Cross-platform | Open-source, clear syntax, comprehensive documentation |
| MASM | Intel syntax | Windows | Microsoft official, powerful but platform-limited |
| GAS | AT&T syntax | Cross-platform | GNU toolchain default, syntax is counterintuitive |
This tutorial exclusively uses the NASM assembler with Intel-style syntax.
Other extensions