8086 Instruction Set String Instruction: Assist. Prof. Dr. Hadeel Nasrat Abdullah
8086 Instruction Set String Instruction: Assist. Prof. Dr. Hadeel Nasrat Abdullah
MOVS
Repeat while not end of string
REP STOS
CX ≠ 0
LODS
Repeat while not end of string and strings
CMPS
REPE/REPZ are equal
SCAS
CX ≠ 0 & ZF = 1
Repeat while not end of string and strings
REPNE/RE CMPS
are not equal
PNZ SCAS
CX ≠ 0 & ZF = 0
Lecture 6: String Instruction
Assist. Prof. Dr. Hadeel N. Abdullah 4
String Instruction Basics
Source DS:SI, Destination ES:DI
You must ensure DS and ES are correct
You must ensure SI and DI are offsets into DS and ES
respectively
Direction Flag (0 = Up, 1 = Down)
CLD - Increment addresses (left to right)
STD - Decrement addresses (right to left)
Solution:
Direction Flag=0, CLD
PA=0A000H
MOV AX, 0H PA=DS*10+DI
MOV DS, AX DS=0000H
MOV ES, AX ES=0000H
MOV AL, 05 SI=0000H
MOV DI, A000H DI=A000H
Counter=CX=0FH=16byte
MOV CX, 0FH
CLD
AGAIN: STOSB
LOOP AGAIN
Lecture 6: String Instruction
Assist. Prof. Dr. Hadeel N. Abdullah 6
Example 2: write an 8086 program to copy a block of 32
consecutive bytes from the block of memory locations starting at
address 2000H in the current Data Segment(DS) to a block of
locations starting at address 3000H in the current Extra Segment
(ES).
Solution:
MOV AX,data-seg
MOV DS, AX
CLD Direction Flag=0, CLD
MOV DI, 00D0H
MOV CX, 0046H DS=data_seg
MOV AL, 45H ES=extra_seg
REPNE
SI=0000H
SCASB DI=00D0H
DEC DI Counter=CX=46H=70byte
MOV [DI], 29H
HLT
Solution:
MOV CX, 64H
MOV AX, F000H Direction Flag=0, CLD
MOV DS, AX
MOV ES, AX DS=F000H
MOV SI, 400H ES=F000H
MOV DI, 600H
SI=0400H
CLD DI=0600H
NXTPT: MOVSB Counter=CX=64H=100byte
LOOP NXTPT
HTL
Solution:
MOV AX, 0H Direction Flag=0, CLD
MOV DS, AX DS=0000H
MOV ES, AX ES=0000H
MOV AL, 05 SI=
DI=A001H
MOV DI, A001H
Counter=CX=0FH=16byte
MOV CX, 0FH
CLD
AGAIN: SCASB
LOOPNE AGAIN
12
Lecture 6: String Instruction
Assist. Prof. Dr. Hadeel N. Abdullah
Homework
1. Match the following