1.
Addressing Modes (Complete)
Definition: Addressing modes describe the different ways in which
the location of an operand is specified in an instruction. They are
essential to understanding how the CPU accesses data from
memory and registers. Different modes are suitable for different
types of tasks like immediate operations, accessing arrays, or
working with pointers.
Types of Addressing Modes (with Concepts):
1. Immediate Addressing:
- The operand (data) is directly included in the instruction.
- Useful for initializing variables with fixed values.
- Example: MOV AL, 05h → Loads 5 directly into register AL.
2. Register Addressing:
- The operand is stored in a register.
- Fast and efficient as it avoids memory access.
- Example: MOV AX, BX → Copies contents of BX into AX.
3. Direct Addressing:
- A memory address is specified directly in the instruction.
- Used to access specific memory locations.
- Example: MOV AX, [1234h] → Loads value at memory address
1234h into AX.
4. Register Indirect Addressing:
- A register holds the address of the operand in memory.
- Allows dynamic memory access (like accessing arrays).
- Example: MOV AX, [BX] → Access memory whose address is
stored in BX.
5. Base Addressing Mode:
- A base register (like BX or BP) and an optional displacement.
- Commonly used to access structure members.
- Example: MOV AX, [BX+04]
6. Indexed Addressing Mode:
- Uses an index register (SI or DI) to traverse arrays.
- Example: MOV AL, [SI] → Access current element of an array.
7. Base + Index Addressing:
- Combines both a base and an index register to calculate address.
- Highly flexible, used in multi-dimensional array access.
- Example: MOV AX, [BX+SI]
8. Relative Addressing:
- Used mainly in jump instructions.
- The target address is relative to the current instruction pointer.
- Example: JMP LABEL
2. Assembly Language
It is a low-level language. It uses a set of English words to be easily
remembered.
e.g. ADD is short of addition, we will use it.
This language is basically for hardware interfacing.
This language also needs a translator to convert code into machine
language, it is called Assembler.
Two commonly used assemblers are:
MASM → Microsoft Assembler
TASM → Turbo Assembler (Borland’s version)
(e.g. MASM 6.12 latest version)
The editor used to write program can be any text-oriented – PUB
comes with MASM, Notepad, edit.
Structure of an Assembly Language:
[Optional] Title – Title of program
// Purpose of program
[Must]
Dosseg – It adjusts the order of different segments
Model – Model name
Stack – Stack size
Code
procedure-name PROC
statement
procedure-name ENDP
. Data
Variable declaration
END
Explanation:
Dosseg → It adjusts the order of different segments: e.g. data,
code, and stack.
Model → Unit and structure type of segments can be
manipulated using:
e.g. Model small
Code segment → List of instructions is written in this code.
Stack size → It is used to change the size of the stack segment.
; → is used for comments
It is not case sensitive.
Every instruction must be written on a different line.
e.g.
ADD AX, BX
Mov AL, DX
One space is must → no restriction on how much space.
* All files will be saved with extension of .ASM
e.g.
Test.ASM
3. Data Definition Directives (4 Variations)
Definition: Data definition directives are used to allocate memory
space and optionally initialize it. They allow programmers to define
constants and variables of different sizes.
Types:
1. DB (Define Byte):
- Allocates 1 byte of memory.
- Example: char DB 'A'
- Used for characters or small numbers.
2. DW (Define Word):
- Allocates 2 bytes (16 bits).
- Example: number DW 1234h
- Used for 16-bit integer values.
3. DD (Define Double Word):
- Allocates 4 bytes (32 bits).
- Example: bigNum DD 12345678h
- Used for long integers or pointers.
4. DQ (Define Quad Word):
- Allocates 8 bytes (64 bits).
- Example: hugeNum DQ 1122334455667788h
- Used for large data values like floating-point numbers.
4. Assembly Instructions
Definition: Instructions are the actual commands given to the CPU
to perform operations such as data transfer, arithmetic, logical
operations, control flow, and memory access.
Categories of Instructions:
- Data Transfer Instructions:
- MOV AX, BX → Transfer data from BX to AX.
- XCHG AX, BX → Exchange values in AX and BX.
- LEA AX, [BX+SI] → Load address of a variable.
- OFFSET → Get memory offset of a variable.
- Arithmetic Instructions:
- ADD AX, BX → AX = AX + BX
- SUB AX, BX → AX = AX - BX
- INC AX → AX = AX + 1
- DEC AX → AX = AX - 1
- Comparison & Branching:
- CMP AX, BX → Compare AX with BX.
- JE, JNE, JL, JG → Conditional jumps depending on result.
- Directives:
- EQU → De ine a constant value.
- PTR → Override data type (e.g., BYTE PTR).
- ORG → Set the origin address for memory placement.
5. Programs
Definition: Assembly programs consist of sequences of instructions
that perform specific tasks. These tasks may include input/output,
arithmetic, string handling, and array manipulation.
Examples:
1. Input a Character:
MOV AH, 01H ; Input function
INT 21H ; Get character from keyboard
MOV BL, AL ; Store it in BL register
2. Display a String:
MOV AH, 09H ; Display function
LEA DX, msg ; Load address of string
INT 21H ; Display string on screen
3. Display Array Elements:
LEA SI, array ; Load base address of array
MOV CX, 05 ; Counter for loop
PRINT_LOOP:
MOV DL, [SI] ; Get element
MOV AH, 02H ; Output function
INT 21H ; Print character
INC SI
LOOP PRINT_LOOP; Repeat for next element
6. Boolean Statements (AND, OR, NOT)
Definition: Boolean operations are bitwise instructions used to
manipulate individual bits within a register. These are essential for
low-level control, masking bits, toggling values, and logic checking.
- AND: Clears bits (used for masking).
- Example: AND AL, 0F0H
- OR: Sets bits (used for enabling flags).
- Example: OR AL, 0CH
- NOT: Inverts all bits.
- Example: NOT AX
These are heavily used in logic conditions and device control at the
hardware level.
7. Loops and Conditions (Theory & Syntax Only)
Definition: Loops repeat a block of code a fixed number of times.
Conditions (using CMP and jumps) allow the program to take
different paths depending on the values of variables.
LOOP Instruction:
MOV CX, 10; Set loop count
LOOP_LABEL:
; Code to repeat
LOOP LOOP_LABEL; CX is decremented and looped
Conditional Execution:
CMP AX, BX; Compare two values
JE Equal_Label; Jump if equal
JNE Not Equal_Label; Jump if not equal
Jump instructions are executed based on CPU flags (Zero, Carry,
Sign, etc.).