Presentation is loading. Please wait.

Presentation is loading. Please wait.

Khaled A. Al-Utaibi  Introduction  The MOV Instruction  The LEA Instruction  The Stack Instructions  The String Data Transfer.

Similar presentations


Presentation on theme: "Khaled A. Al-Utaibi  Introduction  The MOV Instruction  The LEA Instruction  The Stack Instructions  The String Data Transfer."— Presentation transcript:

1 Khaled A. Al-Utaibi alutaibi@uoh.edu.sa

2  Introduction  The MOV Instruction  The LEA Instruction  The Stack Instructions  The String Data Transfer Instructions  The I/O Instructions

3  The data movement instructions that is covered in these slides are listed below: − MOV − LEA − PUSH − POP − MOVSB / MOVSW − LODSB / LODSW − STOSB / STOSW − IN − OUT

4  The general format of a MOV instruction is − MOV destination, source  The MOV instruction copies the contents of the source operand into the destination operand.  All allowed combinations of the two operands are listed below: − Register, Memory(e.g., MOV AX, LIST) − Memory, Register(e.g., MOV LIST, AX) − Register, Register(e.g., MOV AX, BX) − Memory, Immediate(e.g., MOV LIST, 4) − Register, Immediate(e.g., MOV AX, 4) − Segment Register, Memory(e.g., MOV ES, LIST) − Memory, Segment Register(e.g., MOV LIST, ES) − Register, Segment Register(e.g., MOV AX, DS) − Segment Register, Register(e.g., MOV DS, AX)

5  The following actions are not allowed with the MOV instruction: − Set the value of the code segment register (CS).  MOV CS, 1000H(Not Allowed) − Copy the value of one segment register to another segment register (should copy to a general register first).  MOV ES, DS(Not allowed)  MOV AX, DS(Use a general register, e.g., AX)  MOV ES, AX − Copy an immediate value to a segment register (should copy to a general register first).  MOV DS, 1000H(Not allowed)  MOV AX, 1000H (Use a general register, e.g., AX)  MOV DS, AX

6  The general format of a LEA instruction is − LEA destination, source − Where:  destination is a 16-bit general-purpose register, and  source is a memory reference  The LEA instruction is not, strictly speaking, a data transfer instruction.  It transfers the offset of a datum, not its contents, a destination operand.  Example: LEA AX, VarName

7  The stack instructions are important instructions that store and retrieve data from the LIFO (last- in, first-out) stack memory.  The 8086 processor supports 4 stack instructions: − PUSH − POP − PUSF (Push Flag Register) − POPF (Pop Flag Register)

8  The general format of a PUSH instruction is − PUSH operand  The PUSH instruction stores the contents of the operand (16-bits) on the stack.  Allowed operands of the PUSH instruction are listed below: − Register(e.g., PUSH AX) − Segment Register(e.g., PUSH DS) − Memory (Word-Sized)(e.g., PUSH MyData)

9  When an operand (2-bytes) is pushed in the stack the following steps occur: − The first (most-significant) data byte moves to the stack segment memory location addressed by (SP-1) − The second (least-significant) data byte moves into the stack segment memory location addressed by (SP-2) − After the data are stored by a PUSH, the contents of the SP register decrement by 2.  Figure 1 shows the operation of the PUSH AX instruction.  This instruction copies the contents of AX onto the stack where address SS:[SP-1]=AH and SS:[SP-2]=AL, and afterwards (SP-2)

10 Figure 1: The effect of the PUSH AX instruction on ESP and stack memory locations 37FFH and 37FEH. This instruction is shown at the point after execution.

11  The general format of a POP instruction is − POP operand  The POP instruction removes 2 bytes from the top of the stack and stores them into the operand (16-bits).  Allowed operands of the POP instruction are listed below: − Register(e.g., POP AX) − Segment Register(e.g., POP DS) − Memory (Word-Sized)(e.g., POP MyData)

12  When data (2-bytes) are popped from the stack the following steps occur: − The first byte of data removed from the stack memory location addressed pointed by SP and is placed into the lower portion of the operand (e.g. BL) − The second byte is removed from stack segment memory location (SP+1) and is placed into upper portion of the operand (e.g. BH) − After removing the 2 bytes from the stack, the contents of the SP register incremented by 2.  Figure 2 shows how the POP BX instruction removes data from the stack and places them into register BX.

13 Figure 2: The POP BX instruction, showing how data are removed from the stack. This instruction is shown after execution.

14  There are 6 string data transfer instructions in 8086 processor: − MOVSB / MOVSW − LODSB / LODSW − STOSB / STOSW.  Each string instruction allows data transfers that are either a single byte or a word.  Before the string instructions are presented, the operation of the direction flag-bit (DF), DI, and SI must be understood as they apply to the string instructions.

15  The direction flag (DF, located in the flag register) selects the auto-increment (DF = 0) or the auto- decrement operation (DF = 1) for the DI (Destination Index) and SI (Source Index) registers during string operations.  The direction flag is used only with the string instructions (i.e., MOVSB, MOVSW, LODSB, LODSW, STOSB, STOSW).  The CLD instruction clears the DF (DF = 0) flag and the STD instruction sets it (DF = 1).  Therefore, the CLD instruction selects the auto- increment mode and STD selects the auto- decrement mode.

16  Whenever a string instruction (e.g. MOVSTB, LODSB, STOSB) transfers a byte, the contents of DI and/or SI are incremented or decremented by 1.  If a word is transferred using a string instruction (e.g. MOVSW, LODSW, STOSW), the contents of DI and/or SI are incremented or decremented by 2.  Only the actual registers used by the string instruction are incremented or decremented.  For example, the STOSB instruction uses the DI register to address a memory location.  When STOSB executes, only the DI register is incremented or decremented without affecting SI.  The same is true of the LODSB instruction, which uses the SI register to address memory data.  A LODSB instruction will only increment or decrement SI without affecting DI.

17  During the execution of a string instruction, memory accesses occur through either or both of the DI and SI registers.  The DI offset address accesses data in the extra segment for all string instructions that use it.  The SI offset address accesses data, by default, in the data segment.

18  The general format of a MOVSB (Move String of Bytes) instruction is − MOVSB  The MOVSB copies the contents of the byte of memory at DS:[SI] into the byte of memory at ES:[DI].  It also automatically increments/decrements the contents of both SI and DI registers.  The MOVSB instruction works as follows: − byte(ES:[DI]) = byte(DS:[SI]) − if (DF = 0) then − SI = SI + 1 − DI = DI + 1 − else − SI = SI - 1 − DI = DI - 1

19  The general format of a MOVSW (Move String of Words) instruction is − MOVSW  The MOVSW copies the contents of the word of memory at DS:[SI] into the word of memory at ES:[DI].  It also automatically increments/decrements the contents of both SI and DI registers by 2.  The MOVSW instruction works as follows: − word(ES:[DI]) = word(DS:[SI]) − if (DF = 0) then − SI = SI + 2 − DI = DI + 2 − else − SI = SI - 2 − DI = DI - 2

20  The general format of a LODSB (Load String of Bytes) instruction is − LODSB  The LODSB copies the contents of the byte of memory at DS:[SI] into the AL register.  It also automatically increments/decrements the contents of the SI register.  The LODSB instruction works as follows: − AL = byte(DS:[SI]) − if (DF = 0) then − SI = SI + 1 − else − SI = SI - 1

21  The general format of a LODSW (Load String of Words) instruction is − LODSW  The LODSW copies the contents of the word of memory at DS:[SI] into the AX register.  It also automatically increments/decrements the contents of the SI register AX by 2.  The LODSW instruction works as follows: − AX = word(DS:[SI]) − if (DF = 0) then − SI = SI + 2 − else − SI = SI - 2

22  The general format of a STOSB(Store String of Bytes) instruction is − STOSB  The STOSB copies the contents of the AL register into the byte of memory at ES:[DI].  It also automatically increments/decrements the contents of the DI register.  The STOSB instruction works as follows: − byte(ES:[DI]) = AL − if (DF = 0) then − DI = DI + 1 − else − DI = DI - 1

23  The general format of a STOSW(Store String of Words) instruction is − STOSW  The STOSW copies the contents of the AX register into the word of memory at ES:[DI].  It also automatically increments/decrements the contents of the DI register by 2.  The STOSW instruction works as follows: − word(ES:[DI]) = AX − if (DF = 0) then − DI = DI + 2 − else − DI = DI - 2

24  The IN and OUT instructions are used for information transfer through the I/O ports.  The 8086 processor supports 2 16 = 65,536 ports.  The ports are numbered from 0000-FFFFH.  Each I/O port can transfer 1 byte of data.  The I/O ports are usually connected to peripheral devices such as the keyboard, video controller, and disk drives.

25  The IN (Input) instruction has 4 forms: − IN AL, immediate − IN AL, DX − IN AX, immediate − IN AX, DX  If the source operand is an immediate value, it identifies a port whose number must be in the range 00-FFH.  If the source operand is the DX register, the contents of the DX register identify a port whose number can be in the range 0000-FFFFH.

26  If the destination operand of an IN instruction is the AL register, the contents of the AL register are set to the contents of the datum present at the specified port.  If the destination operand is the AX register, the contents of the AL register are the contents of the datum present at the specified port, and the contents of the AH register are set to the contents of the datum present at the port of the next higher number.

27  The operation of the Instruction IN AL, 4 is as follows: − AL = byte(Input Port # 4)  The operation of the Instruction IN AX, 4 is as follows: − AL = byte(Input Port # 4) − AH = byte(Input Port # 5)

28  The OUT(Output) instruction has 4 forms: − OUT immediate, AL − OUT DX, AL − OUT immediate, AX − OUT DX, AX  The OUT instructions specify ports as destination operands and the AL and AX registers as source operands in a manner altogether analogous to that used by the IN instruction.  The only difference between IN and OUT is that the former transfers data from a register to a port while the latter transfer data from a port to a register.

29  The operation of the Instruction OUT 4, AL is as follows: − byte(Input Port # 4) = AL  The operation of the Instruction OUT 4, AX is as follows: − byte(Input Port # 4) = AL − byte(Input Port # 5) = AH


Download ppt "Khaled A. Al-Utaibi  Introduction  The MOV Instruction  The LEA Instruction  The Stack Instructions  The String Data Transfer."

Similar presentations


Ads by Google