Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

11/25/2022

(6)
String Group

Dr. Mazin H. Aziz 2nd-Class Microprocessor 11/21/2022 1

Dr. Mazin H. Aziz 2nd-Class Microprocessor 11/21/2022 2

1
11/25/2022

Dr. Mazin H. Aziz


2nd-Class
Microprocessor

11/21/2022 3

INST. OPERANDS FUNCTION

Copy byte at DS:[SI] to ES:[DI].


Update SI and DI.

Algorithm:
NO
ES:[DI] = DS:[SI]
MOVSB OPERAND

if DF = 0 then
SI = SI + 1 , DI = DI + 1
else
SI = SI – 1 , DI = DI – 1
11/21/2022 4
Dr. Mazin H. Aziz 2nd-Class Microprocessor

2
11/25/2022

INST. OPERANDS FUNCTION

Copy word at DS:[SI] to ES:[DI].


Update SI and DI.

Algorithm:
NO
ES:[DI] = DS:[SI]
MOVSW OPERAND ES:[DI+1] = DS:[SI+1]
or ES:[DI-1] = DS:[SI-1]

if DF = 0 then
SI = SI + 2 , DI = DI + 2
else
SI = SI – 2 , DI = DI – 2
11/21/2022 5
Dr. Mazin H. Aziz 2nd-Class Microprocessor

Source Destination
DS : SI ES : DI
MOVSB

MOVSW

11/21/2022 6
Dr. Mazin H. Aziz 2nd-Class Microprocessor

3
11/25/2022

INST. OPERANDS FUNCTION

Copy byte at DS:[SI] to ES:[DI].


Update SI and DI.

Algorithm:
NO
ES:[DI] = DS:[SI]
MOVSB OPERAND

if DF = 0 then
SI = SI + 1 , DI = DI + 1
else
SI = SI – 1 , DI = DI – 1
11/21/2022 7
Dr. Mazin H. Aziz 2nd-Class Microprocessor

INST. OPERANDS FUNCTION

Copy byte at DS:[SI] to ES:[DI].


Update SI and DI and repeat MOVSB
until CX=0.
Algorithm:
REP NO
ES:[DI] = DS:[SI]
MOVSB OPERAND
CX = CX-1
if CX <> 0 then
if DF = 0 then
SI = SI + 1 , DI = DI + 1 , MOVSB
else
SI = SI – 1 , DI = DI – 1 , MOVSB
else stop MOVSB
11/21/2022 8
Dr. Mazin H. Aziz 2nd-Class Microprocessor

4
11/25/2022

INST. OPERANDS FUNCTION

Copy byte at DS:[SI] to AL


Update SI only.

Algorithm:
NO
AL= DS:[SI]
LODSB OPERAND

if DF = 0 then
SI = SI + 1
else
SI = SI – 1
11/21/2022 Dr. Mazin H. Aziz 2nd-Class Microprocessor 9

INST. OPERANDS FUNCTION

Copy word at DS:[SI] to AX


Update SI only.

Algorithm:
NO
AX= DS:[SI]
LODSW OPERAND

if DF = 0 then
SI = SI + 2
else
SI = SI – 2
11/21/2022 10
Dr. Mazin H. Aziz 2nd-Class Microprocessor

10

5
11/25/2022

INST. OPERANDS FUNCTION

Copy byte at AL to ES:[DI]


Update DI only.

Algorithm:
NO
ES:[DI] = AL
STOSB OPERAND

if DF = 0 then
DI = DI + 1
else
DI = DI – 1
11/21/2022 Dr. Mazin H. Aziz 2nd-Class Microprocessor 11

11

INST. OPERANDS FUNCTION

Copy byte at AL to ES:[DI]


Update DI and repeat STOSB until
CX=0.
Algorithm:
REP NO
ES:[DI] = AL
STOSB OPERAND
CX = CX-1
If CX <> 0 then
if DF = 0 then
DI = DI + 1 , STOSB
else
DI = DI – 1 , STOSB
else stop STOSB
11/21/2022 12
Dr. Mazin H. Aziz 2nd-Class Microprocessor

12

6
11/25/2022

INST. OPERANDS FUNCTION

Copy word at AX to ES:[DI]


Update DI and repeat STOSW until
CX=0.
Algorithm:
REP NO
ES:[DI] = AX
STOSW OPERAND
CX = CX-1
If CX <> 0 then
if DF = 0 then
DI = DI + 2 , STOSW
else
DI = DI – 2 , STOSW
else stop STOSW
11/21/2022 13
Dr. Mazin H. Aziz 2nd-Class Microprocessor

13

INST. OPERANDS FUNCTION

Compare byte at DS:[SI] with ES:[DI].


Update SI and DI and repeat CMPSB
until CX=0 or ZF=0.
Algorithm:
REPE NO
DS:[SI] - ES:[DI]
CMPSB OPERAND
CX = CX-1
If CX <> 0 AND ZF = 1 then
if DF = 0 then
SI = SI + 1 , DI = DI + 1 , CMPSB
else
S, Z, O, A, C & P SI = SI – 1 , DI = DI – 1 , CMPSB
FLAGS are Affected else stop CMPSB
11/21/2022 14
Dr. Mazin H. Aziz 2nd-Class Microprocessor

14

7
11/25/2022

INST. OPERANDS FUNCTION

Compare byte at DS:[SI] with ES:[DI].


Update SI and DI and repeat CMPSB
until CX=0 or ZF=1.
Algorithm:
REPNE NO
DS:[SI] - ES:[DI]
CMPSB OPERAND
CX = CX-1
If CX <> 0 AND ZF = 0 then
if DF = 0 then
SI = SI + 1 , DI = DI + 1 , CMPSB
else
S, Z, O, A, C & P SI = SI – 1 , DI = DI – 1 , CMPSB
FLAGS are Affected else stop CMPSB
11/21/2022 15
Dr. Mazin H. Aziz 2nd-Class Microprocessor

15

INST. OPERANDS FUNCTION

Compare word at DS:[SI] with ES:[DI].


Update SI and DI and repeat CMPSB
until CX=0 or ZF=1.
Algorithm:
REPNZ NO
DS:[SI] - ES:[DI]
CMPSW OPERAND
CX = CX-1
If CX <> 0 AND ZF = 0 then
if DF = 0 then
SI = SI + 2 , DI = DI + 2 , CMPSW
else
S, Z, O, A, C & P SI = SI – 2 , DI = DI – 2 , CMPSW
FLAGS are Affected else stop CMPSB
11/21/2022 16
Dr. Mazin H. Aziz 2nd-Class Microprocessor

16

8
11/25/2022

INST. OPERANDS FUNCTION

Compare byte at AL with ES:[DI].


Update DI and repeat SCASB until
CX=0 or ZF=0.
Algorithm:
REPE NO
AL - ES:[DI]
SCASB OPERAND
CX = CX-1
if CX <> 0 AND ZF = 1 then
if DF = 0 then
DI = DI + 1 , SCASB
else
S, Z, O, A, C & P DI = DI – 1 , SCASB
FLAGS are Affected else stop SCASB
11/21/2022 17
Dr. Mazin H. Aziz 2nd-Class Microprocessor

17

INST. OPERANDS FUNCTION

Compare byte at AL with ES:[DI].


Update DI and repeat SCASB until
CX=0 or ZF=1.
Algorithm:
REPNE NO
AL- ES:[DI]
SCASB OPERAND
CX = CX-1
If CX <> 0 AND ZF = 0 then
if DF = 0 then
DI = DI + 1 , SCASB
else
S, Z, O, A, C & P DI = DI – 1 , SCASB
FLAGS are Affected else stop SCASB
11/21/2022 18
Dr. Mazin H. Aziz 2nd-Class Microprocessor

18

9
11/25/2022

INST. OPERANDS FUNCTION

Compare word at AX with ES:[DI].


Update DI and repeat SCASB until
CX=0 or ZF=1.
Algorithm:
REPNZ NO
AX - ES:[DI]
SCASW OPERAND
CX = CX-1
If CX <> 0 AND ZF = 0 then
if DF = 0 then
DI = DI + 2 , SCASW
else
S, Z, O, A, C & P DI = DI – 2 , SCASW else stop
11/21/2022
FLAGS are Affected SCASB 19
Dr. Mazin H. Aziz 2nd-Class Microprocessor

19

MOV AX, code


MOV AX, code MOV DS,AX
MOV DS,AX MOV AX,EXTRA
MOV ES,AX MOV ES,AX
MOV DI,OFFSET dest LEA DI,ES:[dest]
LEA SI,srs MOV SI,OFFSET DS:[srs]
MOV CX,ssize MOV CX,DS:[ssize]
CLD CLD
REP REP
MOVSB MOVSW
HLT HLT
Dest db 1000 dup (?) Srs dw 1000 dup (?)
SrS db 1000 dup (?) Ssize dw 50
Ssize dw 50 EXTRA SEGMENT
Dest dw 1000 dup (?)
EXTRA ENDS
11/21/2022 Dr. Mazin H. Aziz 2nd-Class Microprocessor 20

20

10
11/25/2022

1. Write a program that compares the upper half of the DOS screen with
its lower half and finds the location of the first character-match.

2. Write a program to clear DOS screen using a delay subroutine to clear in


slow motion from top-to-bottom.

3. Repeat 2 above but from bottom-to-top of the screen.

4. Write a program to store the current screen then retrieve it.

5. Write a program to find the row and column of the first ‘A’ on the DOS
screen and save them at Row and Column, respectively.
11/21/2022 Dr. Mazin H. Aziz 2nd-Class Microprocessor 21

21

11/21/2022 Dr. Mazin H. Aziz 2nd-Class Microprocessor 22

22

11

You might also like