Data Movement Instructions:
This instruction type copies a word or byte from source to destination. The destination can be a register or memory. The source can be a register, a memory location or an immediate data. No flags are affected after execution of MOV instruction.
Types of Data Movement Instructions in 8086:
- Register to Register Transfers
- Memory to Register & Register to Memory Transfers
- Immediate to Register & Immediate to Memory Transfers
- I/O Transfers (Input/Output Instructions)
- Stack Operations (PUSH & POP)
- Flag Transfers
- Address Transfer Instructions
1. Register to Register Transfer
These instructions transfer data between general-purpose registers.
🔹 Example:
2. Memory to Register & Register to Memory Transfers
These instructions move data between memory and registers.
🔹 Examples:
📌 Note:
- Memory-to-memory transfers are not allowed directly.
- Only MOV, XCHG, and LEA can access memory directly.
3. Immediate to Register & Immediate to Memory Transfers
These instructions transfer an immediate value (constant) to a register or memory.
🔹 Examples:
4. I/O Transfers (Input/Output Instructions)
Used for communication with I/O devices.
In Instruction copies data from a port to destination which may AL or AX i.e. Accumulator register.
🔹 Examples:
5. Stack Operations (PUSH & POP)
- Stack operations store and retrieve data using the stack.
- This instruction stores the contents of source on to the stack.
- The source can be a general purpose register, segment register or memory.
- No flags are affected by this instruction
- This instruction copies a word from stack segment pointed by SP to destination.
- The destination can be a general purpose register, a segment register or a memory location.
- After copying, SP is automatically incremented by 2.
- No flags are affected by POP instruction
🔹 Examples:
📌 Note: The stack works on LIFO (Last In, First Out) principle.
6. Flag Transfers
- Moves data between flags and registers.
Pop flags from stack
- This instruction is used to store a word from memory location at top of the stack
- The SP (Stack Pointer) is Incremented by 2.
🔹 Example: POPF
PUSHF: Push flags to stack
General form: PUSHF
- This instruction pushes the flag register contents on to the stack. Higher byte of flag is stored first and then lower byte of the flag is stored.
- The SP is decremented by 2.
- No flags are affected.
🔹Example: PUSHF
Load AH from lower byte of flag
General form: LAHF
- This instruction copies lower byte of flag register to AH register.
- No flags are affected.
🔹 Example: LAHF
SAHF: Store AH register to lower byte of flag register
General form: LAHF
- This instruction copies contents of AH register to lower byte of flag register.
- Depending upon the bits of AH register, the flags in the lower byte of flag register will be set or reset.
🔹 Example: SAHF
🔹 Examples:
7. Address Transfer Instructions
LEA - Load Effective Address
Used to load addresses into registers.
General form: LEA Register, source
- This instruction loads the effective address of destination operand into the source register.
- No flags are affected.
🔹 Example:
LEA BX, NUM1
LDS- Load Register and DS with words from memory
General form: LDS Register, Memory address of first word
- This instruction copies a word from memory into register specified. It then copies a word from next memory locations into DS/ES.
- No flags are affected.
🔹 Example:
LDS BX, [5000H]
🔹 Examples:
📌 LEA (Load Effective Address) loads the address of a memory operand, whereas LDS & LES load a segment register along with an offset.
8) XCHG: Exchange
General form: XCHG destination, source
- This instruction exchanges contents of source and destination.
- Source and destination both cannot be memory locations.
- Source and destination must be of same size (i.e. both must be bytes or both must be words).
- Segment register cannot be used with this instruction.
- No flags are affected by this instruction.
🔹 Examples:
XCHG AX, DX
XCHG BL, CL
XCHG [5000H], AX
9) IN: Copy data from a port
General form: IN Accumulator (AX or AL), Port
- This instruction copies data from a port to AL or AX register.
- If an 8 bit port is read, the data will go into AL.
- If a 16 bit port is read, the data will go to AX.
- No flags are affected.
🔹 Example
1) MOV DX, 8000H ; move port address into DX
IN AL, DX
2) MOV DX, 8080H ; move port address into DX
IN AX, DX
10) OUT: Output a byte or word to a port
General form: OUT Port, Accumulator (AX or AL)
This instruction copies a byte from Al to a port or a word from AX to a port.
🔹 Examples:
OUT 81H, AL
OUT 46H, AX
No flags are affected by this instruction.
11) XLAT: Translate a byte in AL
General form: XLAT
- This instruction is used to translate a byte from one code to another code.
- It replaces a byte in AL register with a byte pointed by BX in a lookup table in memory.
- Before using this instruction lookup table must be present in memory. Starting address of table is loaded in BX register. The byte to be translated is loaded in AL.
- AL -> DS : [ BX + AL ]
- The value in AL is added to BX. This new value will be used as pointer in data segment.
- From the location, pointed by [BX+AL], data will be transferred to AL.
- No flags are affected by this instruction. ow to find ASCII value of a decimal digit (0 – 9) present in AL.
ASSUME CS: CODE, DS: DATA
DATA SEGMENT
ASCII_CODES DB 30H,31H,32H,33H,34H,35H,36H,37H,38H,39H
DIGIT DB 05 ; Find ASCII code of 5
RES DB ? ; To store the result i.e. ASCII code
DATA ENDS
CODE SEGMENT
MAIN:
MOV AX, DATA ; Initialize data segment
MOV DS, AX
MOV BX, OFFSET ASCII_CODES ; Find offset of table
MOV AL, DIGIT ; Move code to AL
XLAT ; Find new code
MOV RES, AL ; Store result
MOV AH, 4CH ; Terminate the program
INT 21H
CODE ENDS
END MAIN
No comments:
Post a Comment