Instruction Set
4-35
CMP
CMP
Flag Settings After Instruction
Examples
This example waits for a character from the serial port. DEC, JCXZ, and JMP implement
a construct equivalent to the C-language
do-while loop. CMP and JNE implement an
if statement within the loop.
Tips
Don’t compare signed values with unsigned values. Compare either two integers or two
unsigned numbers.
Related Instructions
If you want to
See
Determine whether particular bits of a component are set to 1
TEST
15
14
13
12
11
10
9
8
7
6
5
4
3
2
1
0
Processor Status
Flags Register
reserved
OF DF
IF TF SF ZF
AF
PF
CF
? = undefined; – = unchanged
OF=1 if result larger than destination operand
OF=0 otherwise
AF=1 if carry or borrow to low nibble
AF=0 otherwise
PF=1 if low byte of result has even number of set bits
PF=0 otherwise
CF=1 for carry or borrow to high-order bit
CF=0 otherwise
–
–
–
res
res
res
SF=1 if result is 0 or positive
SF=0 if result is negative
ZF=1 if result equal to 0
ZF=0 if result not equal to 0
; loop for a maximum number of times or until a
; serial-port character is ready
MOV
CX,100h
; set up counter
LOOP_TOP:
CHAR_READY
; read character into AH (macro)
CMP
AH,0
; is a character ready?
JNE
GOT_CHAR
; if so, then jump out with character
DEC
CX
; subtract 1 from counter
JCXZ
NO_CHAR
; if CX is 0, jump out without character
JMP
LOOP_TOP
; if not, jump to top of loop
GOT_CHAR:
...
NO_CHAR:
...
Содержание 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...