1.Introduction to x86
x86 is a CISC architecture introduced by Intel in 1978, named after early processor models (such as 8086). Its core features include complex instruction set design and backward compatibility, supporting a smooth transition from 16-bit to 64-bit. Throughout its historical evolution, the 80386 marked the beginning of the 32-bit era, while AMD64 (x86-64) achieved 64-bit extension, and multi-core and process optimizations (such as 5nm) continue to enhance performance. On a technical level, x86 strengthens computing power through hyper-threading, SIMD instruction sets (such as AVX), and heterogeneous computing (integrated AI acceleration units), dominating the fields of PCs, servers, and high-performance computing. Compared to the ARM architecture, x86 is known for its high performance and mature ecosystem, but faces competitive pressure from ARM in the mobile sector and the open-source RISC-V architecture. Future trends focus on heterogeneous integration (CPU+GPU/NPU) and energy efficiency optimization, maintaining its core position in AI, cloud computing, and other fields.
2. Environment Configuration
1. Search for DOSBox in your browser
Website:DOSBox, an x86 emulator with DOS

2. Open DOSBox

3. Mount the working directory
Command: masm c d:\masm


3. Basic Syntax and Commands of Assembly Language
1. Data Types and Definitions
·Basic Types: Byte (8 bits), Word (16 bits), Double Word (32 bits), Quad Word (64 bits)
2. Expressions and Operators
oArithmetic Operations: +, -, *, / (only for compile-time calculations).
oLogical Operations: AND, OR, XOR, commonly used for bit manipulation.
oRelational Operations: EQ (equal), NE (not equal), used for conditional assembly.
3. Identifiers and Reserved Words
oNaming Rules: Must start with a letter or underscore, can include numbers, case-sensitive.
oReserved Words: Instruction mnemonics (e.g., MOV), register names (e.g., EAX), pseudo-instructions (e.g., SECTION) cannot be used as identifiers.
4. Basic Instruction Types
1. Data Transfer Instructions
·MOV copies data from the source operand to the destination operand. Example: MOV AX, 5 (stores the immediate value 5 into register AX)
·PUSH / POP pushes/pops data to/from the stack. Example: PUSH AX (pushes the value of AX onto the stack)
·LEA loads an effective address into a register. Example: LEA BX, [SI+10] (stores the address of SI+10 into BX)
2. Arithmetic Operation Instructions
·ADD / SUB performs addition/subtraction. Example: ADD AX, BX (AX = AX + BX)
·MUL / DIV performs unsigned multiplication/division. Example: MUL BL (AX = AL * BL)
·INC / DEC increments/decrements the operand. Example: INC CX (CX = CX + 1)
3. Logical Operation Instructions
·AND / OR / XOR / NOT performs bitwise logical operations. Example: AND AL, 0x0F (clears the high 4 bits of AL)
·SHL / SHR performs logical left/right shifts. Example: SHL AX, 1 (shifts AX left by 1 bit, equivalent to multiplying by 2)
4. Control Transfer Instructions
·JMP unconditionally jumps to a specified address. Example: JMP label (jumps to the label “label”)
·CALL / RET calls a subroutine/returns from a subroutine. Example: CALL subroutine (calls the subroutine “subroutine”)
·Conditional Jump Instructions jump based on flags (e.g., ZF, CF):
oJE / JZ (jump if equal or zero)
oJNE / JNZ (jump if not equal or non-zero)
oJG / JGE (jump if greater/greater than or equal)
oJL / JLE (jump if less/less than or equal)
5. Comparison and Test Instructions
·CMP compares two operands, sets flags but does not modify operands. Example: CMP AX, BX (compares AX and BX)
·TEST performs a bitwise AND operation on two operands, setting flags. Example: TEST AL, 0x01 (tests if the least significant bit of AL is 1)
2. Processor Control Instructions
·NOP is a no-operation (commonly used for padding or delays).
·HLT halts the processor until an interrupt occurs.
·INT triggers a software interrupt. Example: INT 0x21 (calls DOS system functions)
3. Assembly Pseudo Instructions (Directives)
There are also some pseudo instructions in assembly language (which do not directly generate machine code, used to guide the assembler):
·DB / DW / DD: define byte/word/double word data. Example: message DB ‘Hello’, 0
·ORG: sets the starting address of the program. Example: ORG 0x100
·EQU: defines a constant. Example: MAX EQU 100
·SECTION: defines a code or data segment. Example: SECTION .text
5. Example

END

