2 - Lecture 4 Micro
2 - Lecture 4 Micro
4
Data Movement Instructions
Introduction
This chapter concentrates on the data
movement instructions: MOV, MOVSX, MOVZX,
PUSH, POP, BSWAP, XCHG, XLAT, IN, OUT,
LEA, LDS, LFS, LGS, LSS. LAHF, AND SAHF,
and the string instructions: MOVS, LODS,
STOS, INS, and OUTS.
The data movement instructions are presented
first because they are more commonly used
and easier to understand.
nidal@mutah.edu.jo, Dr. Nidal Al-Dmour 2
The Opcode
The opcode selects the operation (addition,
subtraction, move, and so on) that is performed
by the microprocessor. The opcode is either one
or two bytes long for most machine language
instructions. The first six bits of the first byte are
the binary opcode. The direction (D) for the data
flow.
R/M
• MOD = 00 memory no displacement
• MOD = 01 memory 8-bit displacement
• MOD = 10 memory 16/32-bit displacement
• MOD = 11 register
Register Assignments
The table is for REG field and R/M field
(MOD=11).
Code W=0(byte) W=1(Word W=1(Double
) Word)
000 AL AX EAX
001 CL CX ECX
010 DL DX EDX
011 BL BX EBX
100 AH SP ESP
101 CH BP EBP
110 DH SI ESI
111 BH DI
nidal@mutah.edu.jo, Dr. Nidal Al-Dmour
EDI 14
PUSH/POP
The PUSH and POP instructions are important
instructions that store and retrieve from the
LIFO (last in, first out) stack memory. The
microprocessor has six forms of the PUSH and
POP instructions. The PUSH and POP
immediate and the PUSHA and POPA (all
registers) forms are not available in the earlier
8086/8088 microprocessors, but are available
to the 80286 through the Pentium 4.
• LDS, LES, LSS, LFS, 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.
LODS
The LODS instruction loads AL, AX, or EAX with
data at the data segment offset address
indexed by the SI register.
LODSB AL=DS:[SI]; SI=SI+1 or SI=Si-1
LDSW AX=DS:[SI]; SI=SI+2 or SI=Si-2
LODSD EAX=DS:[SI]; SI=SI+4 or SI=Si-4
LODS LIST AL=DS:[SI]; SI=SI+1orSI=Si-1(IF list is a BYTE)
LODS DATA1 AX=DS:[SI]; SI=SI+2orSI=Si-2(IF DATA1 is a word)
LODS PROG EAX=DS:[SI]; SI=SI+4orSI=Si-4(IF PROG is double
nidal@mutah.edu.jo, Dr. Nidal Al-Dmour 32
word)
double WORD
MOVS
One of the more useful string data transfer
instructions which transfers data from one
memory location to another. This is the only
memory to memory transfer allowed. The
MOVS instruction transfers a byte, word, or
double word from the data segment location
addressed by SI to the extra segment location
addressed by DI.
IN and OUT
• The two I/O instructions transfer data between an I/O device and the
accumulator (AL, AX, and EAX). An IN instruction transfers data from
an external I/O device to AL, AX, EAX; an OUT transfers data from AL,
AX, EAX to an external I/O device.
• 16-bit I/O address means there are up to 64K I/O devices possible in
a system.
BSWAP
The BSWAP (byte swap) instruction is available
only in the 80486 and above . This instruction
takes the content of any 32 bit register and
swaps the first byte with the fourth and the
second byte with the third.
EAX=00112233
BSWAP EAX
EAX=33221100