8086 Programming Data Transfer Instructions Push and Pop Instructions Last in first out. The PUSH instruction transfers two bytes to the top of the stack. 037FF AX 6AB3 6A 037FE B3 037FD -2 + SP SS 07FF stack segment 0300 *16 03000 + The effect of PUSH AX instruction PUSH CX [SS:SP-1] CH [SS:SP-2] CL SP SP-2 1 Symbolic PUSH reg16 PUSH seg PUSH mem Example PUSH BX PUSH DS PUSH [DI+2] PUSHA PUSHA PUSHF PUSHF Table The PUSH instructions Note 16-bit register Segment register memory Save all 16-bit registers Save flags The PUSHA instruction pushes all the internal registers onto the stack in the following order: AX, CX, DX, BX, SP, BP, SI, DI. The value of the SP is that before the PUSHA instruction. The PUSHF (push flag) instruction copies the contents of the flag register to the stack. 2 The POP instruction performs the inverse operation of a PUSH instruction. 037FF BX 6A 6A 037FE B3 B3 037FD 2 + SP SS 07FD stack segment 0300 *16 03000 + The effect of POP BX instruction POP BX BL BH SP [SS:SP] [SS:SP+1] SP+2 3 -d300:7f0l10 0300:07F0 FA 8B F4 2E 89 36 D4 04-8C D6 2E 89 36 D2 04 B8 .....6......6... -u100l7 1582:0100 B8B36A 1582:0103 50 1582:0104 5B 1582:0105 CD20 MOV PUSH POP INT AX,6AB3 AX BX 20 -r AX=0000 BX=0000 CX=0000 DX=0000 SP=07FF BP=0000 SI=0000 DI=0000 DS=1582 ES=1582 SS=0300 CS=1582 IP=0100 NV UP EI PL NZ NA PO NC 1582:0100 B8B36A MOV AX,6AB3 -t AX=6AB3 BX=0000 CX=0000 DX=0000 SP=07FF BP=0000 SI=0000 DI=0000 DS=1582 ES=1582 SS=0300 CS=1582 IP=0103 NV UP EI PL NZ NA PO NC 1582:0103 50 PUSH AX -t AX=6AB3 BX=0000 CX=0000 DX=0000 SP=07FD BP=0000 SI=0000 DI=0000 DS=1582 ES=1582 SS=0300 CS=1582 IP=0104 NV UP EI PL NZ NA PO NC 1582:0104 5B POP BX -t AX=6AB3 BX=6AB3 CX=0000 DX=0000 SP=07FF BP=0000 SI=0000 DI=0000 DS=1582 ES=1582 SS=0300 CS=1582 IP=0105 NV UP EI PL NZ NA PO NC 1582:0105 CD20 INT 20 - 4 The XCHG instruction Performs a register-to-register or register-to-memory swap XCHG AX,BX AX XCHG AL,BH AL XCHG [SI],DX [DS:SI] BX BH DX The LAHF and SAHF instructions LAHF SAHF AH Flagslow Flagslow AH 5 The LEA instruction Loads the effective address of the source to the destination LEA BX,NUMB ;NUMB is assumed to point at the byte at location 10FD in the data segment. BL FD BH 10 LEA BX,NUMB = MOV BX,OFFSET NUMB LEA BX,[DI] ; BX DI MOV BX,[DI] ; BX [DI] Example: 6 offset directive can be used with simple operands such as LIST. But cannot be used for operands such as [di], LIST[di], .. Using offset directive the assembler calculates the offset address, while in case of LEA the microprocessor calculates. Hence, MOV …offset is faster. LEA cx,[bx+si] ; CX (BX+SI) mod 64K If bx=2f00 H; si=10d0H cx 3fd0H if bx=ff00H, si=1000H cx 0f00H The LDS AND LES instructions LDS BX,DWORD PTR[SI] BL [SI]; BH [SI+1] DS [SI+3:SI+2]; in the data segment LES BL ES BX,DWORD PTR[SI] [SI]; BH [SI+1] [SI+3:SI+2]; in the extra segment 7 7F 057FF 00 057FF 6A 6A 057FE B3 B3 057FD BX DI DS 07FD data segment 0500 *16 05000 + The effect of LDS BX,[DI] Instruction 8 String Instructions Instructions for moving large blocks of data or strings. For all these instructions the memory source is DS:SI and the destination is ES:DI. The offset memory pointers, SI and DI are automatically incremented or decremented depending on the state of DF. STOS Stores AL or AX at the extra segment memory location addressed by the DI register; if DF = 0, increment DI, else decrement DI STOSB STOSW ES:[DI] AL If DF = 0, DI DI+1 If DF = 1, DI DI-1 ES:[DI] ES:[DI+1] AL AH If DF = 0, DI DI+2 If DF = 1, DI DI-2 LODS Loads AL or AX with the data stored at the data segment memory location addressed by the SI register; if DF = 0, increment SI, else decrement SI 9 LODSB LODSW AL DS:[SI] If DF = 0, SI SI+1 If DF = 1, SI SI-1 AL DS:[SI] AH DS:[SI+1] If DF = 0, SI SI+2 If DF = 1, SI SI-2 MOVS Transfers data from a memory location to another. This is the only memory-to- memory transfer allowed. The MOVS instruction transfer a byte or a word from the data segment location addressed by the SI to the extra segment location addressed by the DI. The pointers then increment or decrement according to DF. MOVSB ES:[DI] If DF = 0, If DF = 1, DS:[SI] SI SI+1 DI DI+1 SI SI-1 DI DI-1 10 MOVSW ES:[DI] DS:[SI] ES:[DI+1] DS:[SI+1] If DF = 0, SI SI+2 DI DI+2 If DF = 1, SI SI-2 DI DI-2 Setting the Direction Flag Two instructions used: STD set direction flag so that the pointers are auto decremented. CLD clear direction flag so that the pointers are auto incremented. 11 Repeat Prefix Preceding the string instructions STOS or MOVS with REP causes these instructions to be repeated a number of times equal to the contents of CX register. REP STOSB ;STOSB ; CX CX-1 ;repeat until CX = 0 d1c66:20l201C66:0020 FE FE FE FE FE FE FE FE-FE FE FE FE FE FE FE FE ................ 1C66:0030 FE FE FE FE FE FE FE FE-FE FE FE FE FE FE FE FE ................ u100l81C66:0100 B0DD MOV AL ,DD 1C66:0102 B92000 MOV CX,0020 1C66:0105 F3 REPZ 1C66:0106 AA STOSB 1C66:0107 CC INT 3 rAX=00FE BX=0000 CX=0000 BP=0000 SI=0000 DI=0020 DX=0000 SP=FFEE DS=1C66 ES=1C66 SS=1C66 CS=1C66 IP=0100 NV UP 12 EI PL NZ NA PO NC DD,1C66:0100 B0DD MOV AL g- AX=00DD BX=0000 CX=0000 BP=0000 SI=0000 DI=0040 DX=0000 SP=FFEE DS=1C66 ES=1C66 SS=1C66 CS=1C66 IP=0107 EI PL NZ NA PO NC 1C66:0107 CC INT NV UP 3 d1c66:20l201C66:0020 DD DD DD DD DD DD DD DD-DD DD DD DD DD DD DD DD ................ 1C66:0030 DD DD DD DD DD DD DD DD-DD DD DD DD DD DD DD DD ................ - 13 XLAT Translate instruction 14 The IN and OUT instructions An IN instruction transfers data from an external I/O device to AL or AX. An OUT instruction transfers data from AL or AX to an external I/O device. The I/O device address is called port address. In direct addressing mode the address is a single byte. In indirect addressing mode the address is two bytes in DX. IN AL,2EH ;AL port 2EH IN AX,2EH ;AL port 26H ;AH port 27H IN AL,DX ;AL port DX IN AX,DX ;AL port DX ;AH port DX+1 OUT 2EH,AL ; port 2EH AL OUT 2EH,AX ; port 26H AL ; port 27H AH ; port DX AL OUT DX,AL 15 OUT DX,AX ; port DX ; port DX+1 AL AH 16 17
© Copyright 2026 Paperzz