1 / 16

Chapter 4

Chapter 4. Data Movement Instructions by Barry B. Brey bbrey@ee.net. MOV et.al. MOV is still the main data transfer instruction, but there are many variations that perform special tasks such as PUSH and POP.

misu
Download Presentation

Chapter 4

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. Chapter 4 Data Movement Instructions by Barry B. Brey bbrey@ee.net

  2. MOV et.al. • MOV is still the main data transfer instruction, but there are many variations that perform special tasks such as PUSH and POP. • We do not often code in hexadecimal machine language, but an understanding tends to help with learning the instruction set and the form of instructions in the memory.

  3. Instruction Modes • Instructions operate in the 16- or 32-bit mode. 16-bit mode instructions are used in DOS and 32-bit mode instructions are used in Windows. • A prefix is used to switch between modes for one instruction at a time. • The register override prefix is 66H and is a byte that precedes the opcode in the memory, • The address override prefix is a 67H and like 66H precedes the opcode in the memory.

  4. The register size prefix switches from 8- and 16-bit registers in the 16-bit mode to 8- and 32-bit registers. • The register size prefix switches from 8- and 32-bit registers to 8- and 16-bit registers in the 32-bit mode. (DOS) MOV EAX,EBX ;reg prefix used (Windows) MOV AX,BX ;reg prefix used

  5. The Opcode

  6. Fields of an Instruction • The D bit in the first byte of an instruction is the direction of data flow either from or to R/M from REG. If D = 0 REG  R/M and if D = 1 R/M  REG • The W bit in the first byte of the opcode either specifies a word (16-bit mode) or a doubleword (32-bit mode). W = 0 byte and W = 1 word/doubleword

  7. The MOD field in the second byte specifies how R/M is used and wether a displacement exists. R/M • MOD = 00 memory no displacement • MOD = 01 memory 8-bit displacement • MOD = 10 memory 16/32-bit displacement • MOD = 11 register

  8. The REG contains the register • The R/M field contains a register or a memory addressing mode as in [BX], etc. • Luckily we do not often need to code into hexadecimal form, that is why we have an assembler. The reason this is explained in the text is so that a feeling for the way instructions are coded is understood and why different instruction contain different numbers of bytes. This knowledge may help when generating efficient code.

  9. Segment Register Moves • Although we do not often directly address segment registers it is important to understand the limitations of the segment register MOV instruction. • Immediate data cannot be moved into a segment register. • CS cannot successfully be loaded with a segment register MOV.

  10. PUSH and POP • PUSH and POP transfer data to and from the stack. The stack is an area of memory that is reused and grows in size with each PUSH and shrinks in size with each POP. • PUSH and POP function with either 16- or 32-bit data. • PUSHF (PUSHFD) and POPF (POPFD) save and restore the flags (EFLAGS) • PUSHA (PUSHAD) and POPA (POPAD) save and restore all the registers

  11. Load Segment and Index • LDS, LES, LSS, LFG, and LGS allow a segment registers and a pointer to both be loaded from memory. LDS BX,BOB ;loads DS and BX with the offset and segment address stored in a 32-bit memory location called BOB.

  12. LEA • The LEA instruction loads the effective address of a memory location into a pointer or index register. • At times we do the same operation with a MOV and the keyword OFFSET MOV BX,OFFSET FRED LEA BX,FRED Both instruction accomplish the same task.

  13. String Data Transfer Instructions • String data transfer instructions are: LODS, STOS, MOVS, INS, and OUTS. • These instructions use the direction flag bit to select the way that a pointer is modified after the instruction. D = 0 auto-increment and D = 1 auto-decrement. • Many of these instructions can be prefixed with a REP (repeat) to repeat the instruction the number of times stored in the CX register.

  14. Miscellaneous • NOP (does nothing) • XCHG (swaps contents) • XLAT (table lookup) • CLC, STC, CMC (modify Carry) • STD and CLD (modify direction) • STI and CLI (modify interrupt)

  15. IN and OUT • The two I/O instructions transfer data between an I/O device and the accumulator (AL, AX, and EAX). • 16-bit I/O address means there are up to 64K I/O devices possible in a system.

More Related