1 / 72

Data Movement Instructions

Data Movement Instructions. Fundamental of Computer System Department of Electrical Engineering University of Indonesia. MOV Revisited. The MOV instruction introduces the ma-chine language instructions available with various addressing modes and instructions

elden
Télécharger la présentation

Data Movement Instructions

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Data Movement Instructions Fundamental of Computer System Department of Electrical Engineering University of Indonesia

  2. MOV Revisited • The MOV instruction introduces the ma-chine language instructions available with various addressing modes and instructions • It is the native binary code that the micro-processor understands and uses as its instructions to control its operation

  3. MOV Revisited (cont’d) • The Opcode • The opcode selects the operation (addition, subtraction, move, etc) performed by the microprocessor • The opcode is either one or two bytes long for most machine language instructions (Fig.4.2)

  4. MOV Revisited (cont’d) • The first six bits of the first byte are the binary op-code • The remaining two bits indicate the direction (D) of the data flow and whether the data are byte or a word (W)

  5. MOV Revisited (cont’d)

  6. MOD field • The MOD field specifies the addressing mode (MOD) or the type of addressing for the selected instruction, and whether the displacement is present with the selected type (table 4.1) • Distinguish the MOV AL, [DI], MOV AL, [DI+2] and MOV Al, [DI+1000H]!

  7. MOD Field for 16-bit instruction

  8. REG and R/M when MOD=11

  9. Example 8BEC = MOV BP,SP

  10. R/M Memory Addressing • If the MOD field contains a 00, 01, or 10, the R/M field takes on a new meaning (Table 4.4) • Figure 4.5 illustrates the machine language version of the 16-bit instruction MOV DL,DI or instruction (8A15H)

  11. R/M Memory Addressing

  12. Example MOV DL,[DI]

  13. Special Addressing Mode • It occurs whenever memory data are referenced by only the displacement mode of addressing for 16-bit instructions  MOV [1000H],DL • Whenever an instruction has only a displacement, the MOD field is always a 00 and the R/M field is always a 110 (see Fig.4.6, Fig.4.7)

  14. 32-bit addressing modes

  15. MOV Revisited (cont’d) • The scaled-index byte (R/M=100) is mainly used when two registers are added to specify the memory address in an instruction (Fig.4.8)

  16. Immediate Instruction • An suppose the instruction MOV WORD PTR [BX +1000H], 1234H that moves 1234 into the word-sized memory location addressed by the sum of 1000H, BX, and DS x 10H • The six byte instruction uses two bytes for the op-code, W, MOD, and R/M fields, two other bytes are the data of 1234H, and the last two are the displacement of 1000H See Fig.4.9

  17. MOV Revisited (cont’d) • Segment MOV Instructions • If the contents of a segment register are moved by the MOV, PUSH, or POP instructions, a special set of register bits (REG field) selects the segment register (see Table.4.6)

  18. Example MOV BX,CS

  19. PUSH/POP • These are important instructions that store and retrieve data from the LIFO stack memory • There are six forms of the PUSH and POP instructions: register, memory, immediate, segment register, flags, and all registers

  20. PUSH • It transfer two or four bytes of data to the stack • PUSHA instruction copies the contents of the internal register set, except the segment registers to the stack • order: AX, BX, CX, DX, BX, SP, BP, SI, and DI • The PUSHF (push flags) instruction copies the content of the flag register to the stack

  21. PUSH Instructions

  22. PUSH AX

  23. POP • It performs the inverse operation of PUSH, i.e., removes data from the stack and places it into the target 16-bit register, or a 16-bit memory location

  24. POP Instructions

  25. POP BX

  26. POP Instructions • The POPA (pop all) removes 16-bit data from the stack and places it into the following registers in order: DI, SI, BP, SP, BX, DX, CX, and AX; this is a reverse order from the way they are placed on the stack by the PUSHA • POPF (pop flags) removes 16-bit number from the stack and places it into the flag register

  27. Initializing the Stack • If the stack area is initialized, load both the SS and SP registers; SS is normally designated with the bottom location of the stack segment • Fig.4.14 shows how the beginning of stack segment is formed and used in PUSH CX • A stack segment is set up as illustrated in example 4.1 and example 4.2

  28. Initializing the Stack

  29. Load-Effective Address (LEA) • LEA • The LEA instruction loads a 16- or 32- bit register with the offset address of the data specified by the operand • E.g., LEA AX,NUMB • Compare: LEA BX,[DI] & MOV BX,[DI] • Understand Example 4.3

  30. LEA Instructions

  31. LDS, LES, LFS, LGS, LSS • LDS, LES, LFS, LGS, LSS • load any 16- or 32-bit register with an offset address and then load the DS, ES, FS, GS, or SS segment register with a segment address

  32. LDS BX,[DI]

  33. String Data Transfers • There are 5 string data transfer instructions: LODS, STOS, MOVS, INS, and OUTS • The Direction Flag • The direction flag (D) -located in the flag register- selects the auto-increment (D=O) or the auto-decrement (D=1) operation for the DI and SI registers during string operations • The CLD instruction clears the D flag (D=0), and the STD instruction sets it (D=1)

  34. String Data Transfers (cont’d) • DI and SI • 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

  35. LODS • The LODS instruction loads AL, AX, or EAX with data stored at the data segment offset address indexed by the SI register

  36. LODS

  37. LODSW

  38. STOS • The STOS instruction stores AL, AX, or EAX at the extra segment memory location addressed by the DI register • The STOSB (stores a byte), STOSW (stores a word) and STOSD (stores a doubleword)

  39. STOS

  40. REP prefix • REP (repetition) is a prefix that can added to any string instruction except LODS • REP causes CX to be incremented or decremented each time a string instruction is executed. When CX reaches 0, the repetition ends.

  41. STOS

More Related