data movement instructions

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

Upload: elden

Post on 15-Jan-2016

23 views

Category:

Documents


0 download

DESCRIPTION

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 - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Data Movement Instructions

Data Movement Instructions

Fundamental of Computer SystemDepartment of Electrical Engineering

University of Indonesia

Page 2: Data Movement Instructions

© Prima d Purnamasari 2009 for 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

Page 3: Data Movement Instructions

© Prima d Purnamasari 2009 for Department of Electrical Engineering University of Indonesia 3

Page 4: Data Movement Instructions

© Prima d Purnamasari 2009 for Department of Electrical Engineering University of Indonesia 4

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)

Page 5: Data Movement Instructions

© Prima d Purnamasari 2009 for Department of Electrical Engineering University of Indonesia 5

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)

Page 6: Data Movement Instructions

© Prima d Purnamasari 2009 for Department of Electrical Engineering University of Indonesia 6

MOV Revisited (cont’d)

Page 7: Data Movement Instructions

© Prima d Purnamasari 2009 for Department of Electrical Engineering University of Indonesia 7

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]!

Page 8: Data Movement Instructions

© Prima d Purnamasari 2009 for Department of Electrical Engineering University of Indonesia 8

MOD Field for 16-bit instruction

Page 9: Data Movement Instructions

© Prima d Purnamasari 2009 for Department of Electrical Engineering University of Indonesia 9

REG and R/M when MOD=11

Page 10: Data Movement Instructions

© Prima d Purnamasari 2009 for Department of Electrical Engineering University of Indonesia 10

Example 8BEC = MOV BP,SP

Page 11: Data Movement Instructions

© Prima d Purnamasari 2009 for Department of Electrical Engineering University of Indonesia 11

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)

Page 12: Data Movement Instructions

© Prima d Purnamasari 2009 for Department of Electrical Engineering University of Indonesia 12

R/M Memory Addressing

Page 13: Data Movement Instructions

© Prima d Purnamasari 2009 for Department of Electrical Engineering University of Indonesia 13

Example MOV DL,[DI]

Page 14: Data Movement Instructions

© Prima d Purnamasari 2009 for Department of Electrical Engineering University of Indonesia 14

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)

Page 15: Data Movement Instructions

© Prima d Purnamasari 2009 for Department of Electrical Engineering University of Indonesia 15

Page 16: Data Movement Instructions

© Prima d Purnamasari 2009 for Department of Electrical Engineering University of Indonesia 16

Page 17: Data Movement Instructions

© Prima d Purnamasari 2009 for Department of Electrical Engineering University of Indonesia 17

32-bit addressing modes

Page 18: Data Movement Instructions

© Prima d Purnamasari 2009 for Department of Electrical Engineering University of Indonesia 18

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)

Page 19: Data Movement Instructions

© Prima d Purnamasari 2009 for Department of Electrical Engineering University of Indonesia 19

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

Page 20: Data Movement Instructions

© Prima d Purnamasari 2009 for Department of Electrical Engineering University of Indonesia 20

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)

Page 21: Data Movement Instructions

© Prima d Purnamasari 2009 for Department of Electrical Engineering University of Indonesia 21

Page 22: Data Movement Instructions

© Prima d Purnamasari 2009 for Department of Electrical Engineering University of Indonesia 22

Example MOV BX,CS

Page 23: Data Movement Instructions

© Prima d Purnamasari 2009 for Department of Electrical Engineering University of Indonesia 23

Page 24: Data Movement Instructions

© Prima d Purnamasari 2009 for Department of Electrical Engineering University of Indonesia 24

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

Page 25: Data Movement Instructions

© Prima d Purnamasari 2009 for Department of Electrical Engineering University of Indonesia 25

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

Page 26: Data Movement Instructions

© Prima d Purnamasari 2009 for Department of Electrical Engineering University of Indonesia 26

PUSH Instructions

Page 27: Data Movement Instructions

© Prima d Purnamasari 2009 for Department of Electrical Engineering University of Indonesia 27

PUSH AX

Page 28: Data Movement Instructions

© Prima d Purnamasari 2009 for Department of Electrical Engineering University of Indonesia 28

Page 29: Data Movement Instructions

© Prima d Purnamasari 2009 for Department of Electrical Engineering University of Indonesia 29

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

Page 30: Data Movement Instructions

© Prima d Purnamasari 2009 for Department of Electrical Engineering University of Indonesia 30

POP Instructions

Page 31: Data Movement Instructions

© Prima d Purnamasari 2009 for Department of Electrical Engineering University of Indonesia 31

POP BX

Page 32: Data Movement Instructions

© Prima d Purnamasari 2009 for Department of Electrical Engineering University of Indonesia 32

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

Page 33: Data Movement Instructions

© Prima d Purnamasari 2009 for Department of Electrical Engineering University of Indonesia 33

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

Page 34: Data Movement Instructions

© Prima d Purnamasari 2009 for Department of Electrical Engineering University of Indonesia 34

Page 35: Data Movement Instructions

© Prima d Purnamasari 2009 for Department of Electrical Engineering University of Indonesia 35

Initializing the Stack

Page 36: Data Movement Instructions

© Prima d Purnamasari 2009 for Department of Electrical Engineering University of Indonesia 36

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

Page 37: Data Movement Instructions

© Prima d Purnamasari 2009 for Department of Electrical Engineering University of Indonesia 37

Page 38: Data Movement Instructions

© Prima d Purnamasari 2009 for Department of Electrical Engineering University of Indonesia 38

LEA Instructions

Page 39: Data Movement Instructions

© Prima d Purnamasari 2009 for Department of Electrical Engineering University of Indonesia 39

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

Page 40: Data Movement Instructions

© Prima d Purnamasari 2009 for Department of Electrical Engineering University of Indonesia 40

LDS BX,[DI]

Page 41: Data Movement Instructions

© Prima d Purnamasari 2009 for Department of Electrical Engineering University of Indonesia 41

Page 42: Data Movement Instructions

© Prima d Purnamasari 2009 for Department of Electrical Engineering University of Indonesia 42

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)

Page 43: Data Movement Instructions

© Prima d Purnamasari 2009 for Department of Electrical Engineering University of Indonesia 43

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

Page 44: Data Movement Instructions

© Prima d Purnamasari 2009 for Department of Electrical Engineering University of Indonesia 44

LODS

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

Page 45: Data Movement Instructions

© Prima d Purnamasari 2009 for Department of Electrical Engineering University of Indonesia 45

LODS

Page 46: Data Movement Instructions

© Prima d Purnamasari 2009 for Department of Electrical Engineering University of Indonesia 46

LODSW

Page 47: Data Movement Instructions

© Prima d Purnamasari 2009 for Department of Electrical Engineering University of Indonesia 47

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)

Page 48: Data Movement Instructions

© Prima d Purnamasari 2009 for Department of Electrical Engineering University of Indonesia 48

STOS

Page 49: Data Movement Instructions

© Prima d Purnamasari 2009 for Department of Electrical Engineering University of Indonesia 49

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.

Page 50: Data Movement Instructions

© Prima d Purnamasari 2009 for Department of Electrical Engineering University of Indonesia 50

STOS

Page 51: Data Movement Instructions

© Prima d Purnamasari 2009 for Department of Electrical Engineering University of Indonesia 51

MOVS

• MOVS instruction transfers data (either byte, word or doubleword) from one memory location to another

• MOVS transfers data from the data segment location addressed by SI to the extra segment location addressed by DI

Page 52: Data Movement Instructions

© Prima d Purnamasari 2009 for Department of Electrical Engineering University of Indonesia 52

MOVS

Page 53: Data Movement Instructions

© Prima d Purnamasari 2009 for Department of Electrical Engineering University of Indonesia 53

Page 54: Data Movement Instructions

© Prima d Purnamasari 2009 for Department of Electrical Engineering University of Indonesia 54

INS

• The INS (input string) instruction transfers data from an I/O device into extra segment memory location addressed by the DI register

• The I/O address is contained in the DX register

Page 55: Data Movement Instructions

© Prima d Purnamasari 2009 for Department of Electrical Engineering University of Indonesia 55

INS

Page 56: Data Movement Instructions

© Prima d Purnamasari 2009 for Department of Electrical Engineering University of Indonesia 56

Page 57: Data Movement Instructions

© Prima d Purnamasari 2009 for Department of Electrical Engineering University of Indonesia 57

OUTS

• The OUTS (output string) transfers data from the data segment location addressed by SI to an I/O device (addressed by DX)

Page 58: Data Movement Instructions

© Prima d Purnamasari 2009 for Department of Electrical Engineering University of Indonesia 58

OUTS

Page 59: Data Movement Instructions

© Prima d Purnamasari 2009 for Department of Electrical Engineering University of Indonesia 59

Page 60: Data Movement Instructions

© Prima d Purnamasari 2009 for Department of Electrical Engineering University of Indonesia 60

Assembler Detail

• Directives– Directives indicate how an operand or section of

program is to be processed by the assembler:• Storing Data in a Memory Segment: DB, DW, DD,

SEGMENT, .DATA, ENDS, DUP, ALIGN -ex.4.12

Page 61: Data Movement Instructions

© Prima d Purnamasari 2009 for Department of Electrical Engineering University of Indonesia 61

Page 62: Data Movement Instructions

© Prima d Purnamasari 2009 for Department of Electrical Engineering University of Indonesia 62

Page 63: Data Movement Instructions

© Prima d Purnamasari 2009 for Department of Electrical Engineering University of Indonesia 63

– ASSUME, EQU, ORG: • the EQU equates a numeric, ASCII, or LABEL to another label -

ex.4.13; • the THIS refers the data as byte or word -ex.4.14; • the ORG (origin) changes the starting offset address of data in

the data segment; • the ASSUME tells the assembler what names have been chosen

for the code, data, extra, and stack segments; • the PROC and ENDP indicate the start and end of a procedure

(subroutine) -ex.4.15; • others are CALLF, CALLN, RETF, RETN, NEAR, FAR -ex.4.16

Page 64: Data Movement Instructions

© Prima d Purnamasari 2009 for Department of Electrical Engineering University of Indonesia 64

Page 65: Data Movement Instructions

© Prima d Purnamasari 2009 for Department of Electrical Engineering University of Indonesia 65

Page 66: Data Movement Instructions

© Prima d Purnamasari 2009 for Department of Electrical Engineering University of Indonesia 66

Assembler Detail

• Memory Organization– The assembler uses two basic formats for

developing software: models and full-segment definitions (available to the MASM assembler)

– Models (ex.4.17): The TINY model (64 KB) and the SMALL model (128 KB), and HUGE model (>128 KB)

Page 67: Data Movement Instructions

© Prima d Purnamasari 2009 for Department of Electrical Engineering University of Indonesia 67

Page 68: Data Movement Instructions

© Prima d Purnamasari 2009 for Department of Electrical Engineering University of Indonesia 68

Assembler Detail (cont’d)

• Full Segment Definitions– Ex.4.18 & Ex.4.19 illustrate the use of full-

segment definitions• Full-segment definitions are also used with the

Borland and Microsoft C/C++ environments for procedures developed in assembly language

– More structured form than the model method– STACK_SEG, DAT_SEG, CODE_SEG, END

MAIN

Page 69: Data Movement Instructions

© Prima d Purnamasari 2009 for Department of Electrical Engineering University of Indonesia 69

Page 70: Data Movement Instructions

© Prima d Purnamasari 2009 for Department of Electrical Engineering University of Indonesia 70

Page 71: Data Movement Instructions

© Prima d Purnamasari 2009 for Department of Electrical Engineering University of Indonesia 71

Assembler Detail

• A Sample Program– Study carefully Ex.4.20

Page 72: Data Movement Instructions

© Prima d Purnamasari 2009 for Department of Electrical Engineering University of Indonesia 72