Data Transfer Instruction 8086 8086 Microprocessor by Ravinder Nath Rajotiya - October 14, 2020October 14, 20200 Share on Facebook Share Send email Mail Print Print Data Transfer Instructions These instructions are used to transfer the data from one operand to another. The source operand could be a literal, in a register, memory, or even an i/o port, as the case may be. Examples of data transfer instructions are: MOV, XCHG, XLAT, LEA, LDS, LES, PUSH, POP, IN and OUT. These instructions are described in the following paragraphs. MOV : Move byte or word to register or memory location. The source can be a register, memory location or an immediate number, the destination can be a register or memory location. But bot the source and destination cannot be memory locations. General syntax format : MOV Destination, Source Examples: MOV CX, 023Bh ; move an immediate 16-bit number in register CX MOV AX, BX ; move register BX content to Register AX MOV AX, [SI][BX] ; move a value from two memory location starting [SI+BX] to register AX MOV AL, array ; move an 8-bit value from the offset of the array in AL register LEA: This instruction is used to load the effective address in the register specified in the instruction. The general format and usage of this instruction is given below: Instruction Format Examples Comments LEA LEA dest., src LEA SI, ARRAY LEA BX, MyName Load the 16 bit offset of array in reg. SI Loads 16 bit offset of MyName in reg. SI This instruction is equivalent to the instruction: MOV SI, offset ARRAYor MOV BX, offset MyName LDS / LES: These two instructions are used to load the Data Segment(DS) or the Extra Segment (ES) registers and the register specified in the instruction from memory. Instruction Format Examples Comments LDS LES LDS dest., src LES dest., src LDS SI, ARRAY LES BX, MyName Loads DS and SI from locations starting from offset ARRAY: Load SI from offset ARRAY and ARRAY+1 and then loads DS from offset ARRAY+2 and ARRAY+3Loads ES and BX from locations starting from offset MyName: Load SI from offset MyName and MyName +1 and then loads DS from offset MyName +2 and MyName +3 XCHG instruction XCHG instruction exchanges two operands that are of same type i.e. byte type or word type. This instruction cannot exchange directly two memory locations, and also operands cannot be segment registers. Format of instruction Instruction Format Examples Comments XCHG XCHG dest., src XCHG DX, AX XCHG AL,BL Exchanges the content of AX and DX Exchanges the content of BL and AL XLAT instruction: This instruction is used to translate the byte in AL using a table in memory pointed by BX. Example: WAP in AL of 8086 to find the square of a number between 1 and 15. Assume that these squares are stored in memory “SQRS” at 2500: 1020, store the result back in memory at offset 1030 SQRS db 1,4,9,16.25.36.49.64.81.100,121,144,169,196, 225 ORG 0 MOV AX, 2500 MOV DS, AX MOV BX, offset SQRS MOV A, number XLAT MOV [1030], AL HLT Stack Operation Instructions in 8086: Two instruction PUSH and POP are used to insert and extract the data from the stack memory. SP is used as a pointer to stack memory whose base segment address is in SS register. The stack pointer is 16 bit pointer into a 20 bit address space formed as SS : SP. SP always points to top of the stack where data is stored. When stack is empty, SP holds the highest address + 1. The operand in both (PUSH and POP) instructions can be a general purpose register, segment register(except CS) or a memory location. PUSH operation : First SP is decremented then the data item inserted at that location. POP operation : First data item from top of stack is extracted then SP incremented Instruction Format Examples Comments PUSH POP PUSH operand POP operand PUSH BX POP CX Copies the BH at SP-1 and BL at SP-2. Thus after the complete execution of PUSH instruction SP is decremented by 2, this new value (SP-2) is the new top of stack. Copies byte from the top of stack in CL and sets SP to SP+1, copies the byte from this location to CH and sets the SP to SP+1. Thus after the complete execution of POP instruction SP is increments by 2, this new value (SP+2) is the new top of stack. LAHF: loads the AH register with the low byte of the Flag. The instruction does not require any operand. SAHF: Stores the AH register content to the low byte of the flag register. As it copies into the low byte of flag register the five flags are affected. PUSHF: This instruction copies the flag register to top of stack. POPF: This instruction copies the top of flag into the flag register, thus this instruction affects all the flags. IN : This instruction copies the data from a port to AL or AX depending on whether an 8-bit or a 16-bit port is being read. Example: IN AL, 80h ; read 8-bit data in AL from the port address 80h IN AX, 40h ; read 16-bit data in AX from the port address 40h OUT : This instruction is used to write an 8-bit or 16-bit data to an 8-bit or 16-bit port Example: MOV DX, 0FE00h ; load DX with the port address OUT DX, AX ; write 16-bit value at the port Examples: WAP an 8086 assembly language program to find the seven-segment code (0-9, A-F) stored in memory from address 2500:2000 and transfer at port address stored in DX. Address 2000 is the offset of seven-segment codes Seven-seg-values db 06h, 5Bh, 4Fh, 66h, 65h, 7Dh, 07h, 7Fh, 6Fh, 77h, 7Ch, 39h, 5Eh, 79h, 71h MOV AX, 2500 MOV DS, AX MOV DX, 0F200h // load input port address in DX MOV BX, offset Seven-seg-value IN AL, DX XLAT MOV DX, 0F201 //output port address OUT DX, AL HLT Share on Facebook Share Send email Mail Print Print