CS401 – Assembly Language
Programming
Chapter 2: Addressing Modes & Data Declaration
(Summary Notes + Questions)
2.1 Data Declaration
- In assembly, variables are declared using directives like `DB`, `DW`, `DD`.
- Example:
```asm
num1 DB 10h ; Declares a byte with value 10h
num2 DW 1234h ; Declares a word with value 1234h
```
Question: What is the size of data declared by `DW`?
Answer: 2 bytes (word size)
2.2 Direct Addressing
- Access memory using a specific address.
- Example:
```asm
MOV AL, [1234h] ; Load byte at memory location 1234h into AL
```
Question: In direct addressing, the operand is a:
Answer: Memory address
2.3 Size Mismatch Errors
- Occurs when you move mismatched data sizes (e.g., byte into word).
- Example:
```asm
MOV AX, [1234h] ; OK if word is at 1234h
MOV AL, [1234h] ; OK if byte is at 1234h
MOV AX, [AL] ; ❌ Invalid – AL is not a valid address
```
Question: What type of error occurs when data size is mismatched in MOV?
Answer: Size mismatch error
2.4 Register Indirect Addressing
- Memory address is stored in a register like `BX`, `SI`, or `DI`.
- Example:
```asm
MOV BX, 1234h
MOV AL, [BX] ; Load byte from memory at address in BX into AL
```
Question: Which registers are used in register indirect addressing?
Answer: BX, SI, DI
2.5 Register + Offset Addressing
- Combines register with constant offset.
- Example:
```asm
MOV BX, 4
MOV AL, [011Fh + BX] ; Effective Address = 0123h
```
Question: If BX = 4 and offset = 011Fh, effective address = ?
Answer: 0123h
2.6 Segment Association
- CS, DS, SS, ES are segment registers. Default for data is DS.
- Instruction fetch uses CS; Stack uses SS.
Question: Which segment is used by default for data variables?
Answer: DS
2.7 Address Wraparound
- Memory addresses are 16-bit. Max address = FFFFh (64KB).
- If address > FFFFh, it wraps around to 0000h.
Question: What is the result of accessing memory at FFFFh + 1?
Answer: 0000h (wraps around)
2.8 Addressing Modes Summary
| Addressing Mode | Example | Description |
| ----------------- | ----------------- | ----------------------- |
| Immediate | MOV AL, 05h | Constant value |
| Direct | MOV AL, [1234h] | Uses memory address |
| Register Indirect | MOV AL, [BX] | Uses register address |
| Register + Offset | MOV AL, [SI + 10] | Adds offset to register |
Question: Which addressing mode is used in `MOV AL, [BX+SI]`?
Answer: Based Indexed Addressing (combination of base and index)