
Instruction Set
4-195
REPE
REPE
Examples
This example compares one string of bytes in memory with another string in the same
segment until it finds a mismatch or all bytes are compared. The microcontroller copies the
bytes, one by one, from first to last. If the strings are different, the following instructions
save the segment and offset of the first mismatch.
; defined in SEG_E segment
STRING1
DB
20h DUP (?)
STRING2
DB
LENGTH STRING1 DUP (?)
; notify assembler: DS and ES specify
; the same segment
ASSUME DS:SEG_E, ES:SEG_E
; set up segment registers with same segment
MOV
AX,SEG_E
; load segment into DS
MOV
DS,AX
; DS points to SEG_E, source
MOV
ES,AX
; ES points to SEG_E, destination
; compare one string for equality to another
; initialize and use both strings
...
; save ES
PUSH
ES
; set up registers and flags
LEA
SI,STRING1
; load source offset (segment = DS)
LES
DI,STRING2
; load dest. offset (segment = ES)
MOV
CX,LENGTH STRING1
; set up counter
CLD
; process string low to high
; compare first string for equality to second string
REPE
CMPSB
; if strings are identical, then jump
JE
EQUAL
; else, load segment of mismatch into ES and offset into DI
DEC
DI
; mismatch is back one byte
LES
DI,STRING2[DI]
JMP
CONTINUE
EQUAL:
...
CONTINUE:
...
; restore ES
POP
ES
Summary of Contents for Am186 Series
Page 1: ...Am186 and Am188 Family Instruction Set Manual February 1997...
Page 10: ...Table of Contents x...
Page 18: ...Programming 1 8...
Page 40: ...Instruction Set Listing 3 14...