Assembly Language Fundamentals: Directives, Operands, Expressions
Assembly Language Directives
Combination Directive
The Combination directive defines how to combine segments with the same name. Possible values include:
- PUBLIC: All segments are concatenated into one.
- STACK: Similar to PUBLIC, but with SS (Stack Segment) on registration addresses.
- COMMON: Overlapping segments created by placing the start of all in the same direction.
- MEMORY: Indicated by LINK segments, dealing with public as MASM, at a specific address.
- AT address: Specifies a segment at a particular memory address.
Class Directive
The Class directive indicates the type of segment, marked with any name.
END Directive
The END directive indicates the end of a module. Upon reaching it, the assembler will ignore any statements that follow.
ASSUME Directive
The ASSUME directive allows you to specify the default values for segment registers.
Labels (Tags)
Labels are declared as name:
where name
is a string.
Data Declaration
Data is declared by type using the rule [name] directive value
, where directive
can be:
- DB: Defines Byte (1 byte)
- DW: Defines Word (2 bytes)
- DD: Defines Double Word (4 bytes)
- DQ: Defines Quad Word (8 bytes)
- DT: Defines Ten Bytes (10 bytes)
You can also use the following directives to declare symbols:
- LABEL: Creates labels for instructions or data.
- EQU: Creates symbols of equality (constant values).
- =: Assigns an absolute value to a symbol.
Structure Declaration
The STRUC directive is used for declaring data structures.
Assembly Instructions
Common categories of assembly instructions include:
- Linear
- Motion (Data Transfer)
- Stack Operations
- Arithmetic
- Configuration
- Compare
- Jumps (Unconditional, Conditional)
- Types of Cycles (Loops)
- Logical Operators
- Displacement (Shift/Rotate)
- Linear/Circular
- Process Control
- Flags
- String Operations
- Load/Store
Operands in Assembly
Operands represent values, registers, or memory locations to be accessed in some way.
Expressions in Assembly
Expressions combine operands and arithmetic or logical operators to calculate a value or an access address.
Types of Operands
The allowed operands are listed below:
Constants
Numbers, strings, or expressions that represent a fixed value.
Direct Addressing
Specifies the memory address to access in the form
segment:offset
.Relocatable Operands
Uses a symbol associated with a memory address and can also be used for calls.
Location Counter ($)
Used to indicate the current location in the segment during assembly. Represented by the symbol
$
and also known as the sentinel.Registers
Refers to general-purpose registers, pointers, index registers, or segment registers.
Based Addressing
Represents a memory address based on one of the base registers (BP or BX).
Indexed Addressing
Represents a memory address based on one of the index registers (SI or DI).
Base-Indexed Addressing
Represents a memory address based on the combination of base and index registers.
Structure Members
The syntax is
variable.field
.variable
is the name of the declared structure, andfield
is the name of the field within the structure.
Assembly Operators & Expressions
Assembly language includes the following types of operators:
- Arithmetic
- Shift
- Relational
- Bitwise
- Index
- Pointer
- Field Name
- Special Purpose
OFFSET Operator
OFFSET expression
: Returns the offset of the operand.
SHORT Operator
SHORT label
: Used for jumps of less than 128 bytes.
LENGTH Operator
LENGTH variable
: Returns the number of elements.
SIZE Operator
SIZE variable
: Returns the size in bytes occupied by a variable.
SEG Operator
SEG expression
: Returns the segment value for an expression.
Example: mov ax, SEG greeting