Assembly Language Basics
Overview
Assembly Language: Low-level language close to machine code.
Focus: Understanding how assembly language works, specifically x86 assembly, rather than mastering a specific type.
Memory Architecture
Little-Endian: Values are written with the least significant byte first.
Example: 32-bit double word
0x1BA583D4is written in memory asD4, 83, A5, 1B.
Instruction Format
Operands: x86 instructions can have 0-3 operands. Typically follows the format
mnemonic destination, source.Mnemonic: Reserved name used for operations (e.g.,
MOVfor copying values).Opcode: The actual operation code interpreted by hardware.
Example:
MOV EAX, 0xCODE5AFE-MOVis the mnemonic,EAXis the destination, and0xCODE5AFEis the source operand.
Registers
Data Registers: Used for arithmetic, logical, and other operations.
32-bit Registers:
EAX,EBX,ECX,EDX16-bit Versions:
AX,BX,CX,DX8-bit Versions:
AH,AL,BH,BL,CH,CL,DH,DL
Primary Accumulator:
EAX(used in I/O and arithmetic operations).Base Register:
EBXCount Register:
ECX(used for loop counts).Data Register:
EDX(also used for I/O operations).
Pointer Registers:
32-bit:
EIP,ESP,EBP16-bit:
IP,SP,BP
EIP: Instruction pointer (offset address of the next instruction).
ESP: Stack pointer (points to the top of the stack).
EBP: Base pointer (references parameter variables in the stack).
Index Registers:
ESI: Source index (used for string operations).
EDI: Destination index (used for string operations).
Control Registers (Flags):
ZF (Zero Flag): Set to
1if the result of an operation is zero;0otherwise.
Segments
Code Segment (CS): Contains executable code.
Data Segment (DS): Contains data.
Stack Segment (SS): Contains stack data.
Extra Segments (ES, FS, GS): For additional data storage.
64-bit vs. 32-bit Registers
64-bit Registers: Use
Rprefix (e.g.,RAX,RBX,RCX,RDX).New Registers:
R8toR15.Stack Size: Larger.
Flags:
RFLAGSregister.
Stack
Purpose: Used for temporary data storage, passing arguments to functions, and saving register values.
Instructions:
PUSH: Stores a value on the stack.POP: Removes a value from the stack.
Last updated