Instruction Set
4-38
CMPS
CMPS
Examples
This example compares for equality one string of nonzero words stored in the segment
specified in ES to another string of nonzero words located in the same segment. The
microcontroller compares the words, one by one, from first to last, unless any two words
being compared don’t match. If both strings are the same, the microcontroller loads 0 into
AX; otherwise, it loads the word that was different in the second string into AX.
; defined in SEG_E segment
STRING1
DW
64 DUP (?)
STRING2
DW
LENGTH STRING1 DUP (?)
; compare strings for equality
; notify assembler: DS and ES point to
; different segments of memory
ASSUME DS:SEG_D, ES:SEG_E
; set up DS and ES with different segment addresses
MOV
AX,SEG_D
; load one segment into DS
MOV
DS,AX
; DS points to SEG_D
MOV
AX,SEG_E
; load another segment into ES
MOV
ES,AX
; ES points to SEG_E
; initialize and use strings
...
; set up registers and flags
LEA
SI,ES:STRING1
; load source offset (segment = ES)
LEA
DI,STRING2
; load dest. offset (segment = ES)
MOV
CX,LENGTH STRING1
; set up counter
CLD
; process string low to high
; compare strings for equality using segment override
; for source
REPE
CMPS
ES:STRING1,STRING2
; if both strings are the same, then jump
JE
SAME
; else, load unequal word into AX
MOV
AX,STRING2[DI]
JMP
CONTINUE
SAME:
; indicate both strings are the same
MOV
AX,0
CONTINUE:
...
Содержание Am186 Series
Страница 1: ...Am186 and Am188 Family Instruction Set Manual February 1997...
Страница 10: ...Table of Contents x...
Страница 18: ...Programming 1 8...
Страница 40: ...Instruction Set Listing 3 14...