Transfer Instructions part 2 Data transfer instructions l

  • Slides: 16
Download presentation
Transfer Instructions part 2

Transfer Instructions part 2

Data transfer instructions l l 1. 2. 3. 4. Data transfer instructions are those

Data transfer instructions l l 1. 2. 3. 4. Data transfer instructions are those which are used to movement of the data from one location to another. Following are the list of instructions under this group Instruction to transfer a word Instructions for input and output port transfer Instructions to transfer the address Instructions to transfer flag registers

Data Transfer instructions l l l PUSH instructions: used to store 16 -bit value

Data Transfer instructions l l l PUSH instructions: used to store 16 -bit value in the stack Push Register (AX, BX, CX, DX, SI, DI, BP, SP) Push Segment Register. (DS, CS, SS, ES) Push Memory ([BX], [BX+SI+7] … ets) Push immediate ( 5, -24, 3 F|h, 10001101|b, …ets)

Data Transfer instructions l l l POP instruction : Used to get 16 -bit

Data Transfer instructions l l l POP instruction : Used to get 16 -bit value from the stack POP Register ( AX, BX, CX, DX, SI, DI, BP, SP) POP Segment Register. (DS, CS, SS, ES) POP Memory ([BX], [BX+SI+7] … ets) POP immediate ( 5, -24, 3 F|h, 10001101|b, …ets)

PUSH & POP l PUSH & POP work with 16 -bit value only. l

PUSH & POP l PUSH & POP work with 16 -bit value only. l PUSH immediate works only with 80186 CPU and later. l The stack use FILO (first in last out) algorithm. l PUSH AX store the register AX in the stack, at first store low (AL) and then store the high (AH). l POP AX get the last value stored in the stack to the register AX, at first the last value is stored in the high (AH) and then other value is stored in the low (AL).

Example #MAKE_COM# ORG 100 h MOV AX, 3000 H MOV SS, AX MOV AX,

Example #MAKE_COM# ORG 100 h MOV AX, 3000 H MOV SS, AX MOV AX, 1234 H MOV BX, 5678 H MOV CX, 9 ABCH PUSH AX PUSH BX PUSH CX POP BX POP AX POP CX HLT

Example #MAKE_COM# ORG 100 h MOV AX, 1000 H MOV SS, AX MOV BP,

Example #MAKE_COM# ORG 100 h MOV AX, 1000 H MOV SS, AX MOV BP, OFFSET DT 1 MOV [BP], 01 H PUSH AX POP AX HLT DT 1 DB 00 H #MAKE_COM# ORG 100 h PUSH BX POP DT 1 PUSH CX POP DT 2 HLT DT 1 DW 00 H DT 2 DW 00 H

PUSHA & POPA instructions l l l Push all general purpose registers AX, CX,

PUSHA & POPA instructions l l l Push all general purpose registers AX, CX, DX, BX, SP, BP, SI, DI in the stack. Original value of SP register (before PUSHA) is used. Pop all general purpose registers DI, SI, BP, SP, BX, DX, CX, AX from the stack. SP value is ignored, it is Popped but not set to SP register). These instructions work only on 80186 CPU and later!

Example MOV BX, 4567 h MOV CX, DT 1 MOV DX, 89 ABh PUSHA

Example MOV BX, 4567 h MOV CX, DT 1 MOV DX, 89 ABh PUSHA HLT DT 1 DW 0123 H ORG 100 H POPA HLT

XLATB instruction l l l The XLATB instruction is used to translate a byte

XLATB instruction l l l The XLATB instruction is used to translate a byte from one code to another code. The instruction replaces a byte in AL register with a byte pointed to by BX & AL. [BX] locate the table in the memory, and AL locate the element inside that table. The XLATB instruction adds the byte in AL to the offset of the start of the table in BX. Copy the byte from the address pointed to by (BX + AL) back into AL. XLATB instruction does not affect any flag.

Example [BX+AL] ==>AL . DATA TABLE 1 DB 'ABCDEFGHIJ', 0, 0, "$" DT 1

Example [BX+AL] ==>AL . DATA TABLE 1 DB 'ABCDEFGHIJ', 0, 0, "$" DT 1 DB 7 . DATA TABLE 1 DB 'AHMED', 0, 0, "$" DT 1 DB 00 H, 00 H . CODE MOV BX, OFFSET TABLE 1 MOV AL, DT 1 XLATB MOV DT 1[0], AL HLT MOV AL, 4 XLATB MOV DT 1[1], AL HLT

Flag Transfer Instructions There is no direct method of altering the other applications-oriented flags.

Flag Transfer Instructions There is no direct method of altering the other applications-oriented flags. l The flag transfer instructions allow a program to transfer these flags to the stack or the AH register. PUSHF instructions. POPF instructions LAHF instructions STC instructions l

PUSHF & POPF instructions l l The PUSHF and POPF instructions used for storing

PUSHF & POPF instructions l l The PUSHF and POPF instructions used for storing the flags in memory used for preserving the state of the flags register while executing a procedure. PUSHF (Push Flags) decrements SP by two and transfers the low-order word of the flags register to the word at the top of stack pointed to by SP. POPF (Pop Flags) transfers specific bits from the word at the top of stack into the low-order byte of the flag register, then increments SP by two.

LAHF & SAHF instructions l l The instructions LAHF and SAHF deal with five

LAHF & SAHF instructions l l The instructions LAHF and SAHF deal with five of the status flags, which are used primarily by the arithmetic and logical instructions. LAHF (Load AH from Flags) copies SF, ZF, AF, PF, and CF to AH. The contents of the remaining bits are undefined. The flags remain unaffected. SAHF (Store AH into Flags) transfers bits from AH into SF, ZF, AF, PF, and CF, respectively.

Example #MAKE_COM# ORG 100 LAHF MOV AH, 00 H SAHF HLT #MAKE_COM# ORG 100

Example #MAKE_COM# ORG 100 LAHF MOV AH, 00 H SAHF HLT #MAKE_COM# ORG 100 POPF MOV AH, VAL 1 PUSHF HLT VAL 1 DB 00 H

Example org 100 h MOV AX, @DATA MOV DS, AX MOV BX, OFFSET DT

Example org 100 h MOV AX, @DATA MOV DS, AX MOV BX, OFFSET DT 1 LAHF MOV [BX], AH HLT DT 1 DB 02 H