* better
[mascara-docs.git] / hw / i386.reference / Jcc.htm
blob8307e7cb451d205c994e80bcc1bcc7f9a4bce009
1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
2 <HTML>
3 <HEAD>
4 <TITLE>80386 Programmer's Reference Manual -- Opcode Jcc</TITLE>
5 </HEAD>
6 <BODY>
7 <B>up:</B> <A HREF="c17.htm">
8 Chapter 17 -- 80386 Instruction Set</A><BR>
9 <B>prev:</B><A HREF="IRET.htm"> IRET/IRETD Interrupt Return</A><BR>
10 <B>next:</B><A HREF="JMP.htm"> JMP Jump</A>
11 <P>
12 <HR>
13 <P>
14 <H1>Jcc -- Jump if Condition is Met</H1>
17 <PRE>
18 Opcode Instruction Clocks Description
20 77 cb JA rel8 7+m,3 Jump short if above (CF=0 and
21 ZF=0)
22 73 cb JAE rel8 7+m,3 Jump short if above or equal
23 (CF=0)
24 72 cb JB rel8 7+m,3 Jump short if below (CF=1)
25 76 cb JBE rel8 7+m,3 Jump short if below or equal
26 (CF=1 or ZF=1)
27 72 cb JC rel8 7+m,3 Jump short if carry (CF=1)
28 E3 cb JCXZ rel8 9+m,5 Jump short if CX register is 0
29 E3 cb JECXZ rel8 9+m,5 Jump short if ECX register is 0
30 74 cb JE rel8 7+m,3 Jump short if equal (ZF=1)
31 74 cb JZ rel8 7+m,3 Jump short if 0 (ZF=1)
32 7F cb JG rel8 7+m,3 Jump short if greater (ZF=0 and
33 SF=OF)
34 7D cb JGE rel8 7+m,3 Jump short if greater or equal
35 (SF=OF)
36 7C cb JL rel8 7+m,3 Jump short if less (SF<>OF)
37 7E cb JLE rel8 7+m,3 Jump short if less or equal
38 (ZF=1 and SF<>OF)
39 76 cb JNA rel8 7+m,3 Jump short if not above (CF=1 or
40 ZF=1)
41 72 cb JNAE rel8 7+m,3 Jump short if not above or equal
42 (CF=1)
43 73 cb JNB rel8 7+m,3 Jump short if not below (CF=0)
44 77 cb JNBE rel8 7+m,3 Jump short if not below or equal
45 (CF=0 and ZF=0)
46 73 cb JNC rel8 7+m,3 Jump short if not carry (CF=0)
47 75 cb JNE rel8 7+m,3 Jump short if not equal (ZF=0)
48 7E cb JNG rel8 7+m,3 Jump short if not greater (ZF=1
49 or SF<>OF)
50 7C cb JNGE rel8 7+m,3 Jump short if not greater or
51 equal (SF<>OF)
52 7D cb JNL rel8 7+m,3 Jump short if not less (SF=OF)
53 7F cb JNLE rel8 7+m,3 Jump short if not less or equal
54 (ZF=0 and SF=OF)
55 71 cb JNO rel8 7+m,3 Jump short if not overflow
56 (OF=0)
57 7B cb JNP rel8 7+m,3 Jump short if not parity (PF=0)
58 79 cb JNS rel8 7+m,3 Jump short if not sign (SF=0)
59 75 cb JNZ rel8 7+m,3 Jump short if not zero (ZF=0)
60 70 cb JO rel8 7+m,3 Jump short if overflow (OF=1)
61 7A cb JP rel8 7+m,3 Jump short if parity (PF=1)
62 7A cb JPE rel8 7+m,3 Jump short if parity even (PF=1)
63 7B cb JPO rel8 7+m,3 Jump short if parity odd (PF=0)
64 78 cb JS rel8 7+m,3 Jump short if sign (SF=1)
65 74 cb JZ rel8 7+m,3 Jump short if zero (ZF = 1)
66 0F 87 cw/cd JA rel16/32 7+m,3 Jump near if above (CF=0 and
67 ZF=0)
68 0F 83 cw/cd JAE rel16/32 7+m,3 Jump near if above or equal
69 (CF=0)
70 0F 82 cw/cd JB rel16/32 7+m,3 Jump near if below (CF=1)
71 0F 86 cw/cd JBE rel16/32 7+m,3 Jump near if below or equal
72 (CF=1 or ZF=1)
73 0F 82 cw/cd JC rel16/32 7+m,3 Jump near if carry (CF=1)
74 0F 84 cw/cd JE rel16/32 7+m,3 Jump near if equal (ZF=1)
75 0F 84 cw/cd JZ rel16/32 7+m,3 Jump near if 0 (ZF=1)
76 0F 8F cw/cd JG rel16/32 7+m,3 Jump near if greater (ZF=0 and
77 SF=OF)
78 0F 8D cw/cd JGE rel16/32 7+m,3 Jump near if greater or equal
79 (SF=OF)
80 0F 8C cw/cd JL rel16/32 7+m,3 Jump near if less (SF<>OF)
81 0F 8E cw/cd JLE rel16/32 7+m,3 Jump near if less or equal (ZF=1
82 and SF<>OF)
83 0F 86 cw/cd JNA rel16/32 7+m,3 Jump near if not above (CF=1 or
84 ZF=1)
85 0F 82 cw/cd JNAE rel16/32 7+m,3 Jump near if not above or equal
86 (CF=1)
87 0F 83 cw/cd JNB rel16/32 7+m,3 Jump near if not below (CF=0)
88 0F 87 cw/cd JNBE rel16/32 7+m,3 Jump near if not below or equal
89 (CF=0 and ZF=0)
90 0F 83 cw/cd JNC rel16/32 7+m,3 Jump near if not carry (CF=0)
91 0F 85 cw/cd JNE rel16/32 7+m,3 Jump near if not equal (ZF=0)
92 0F 8E cw/cd JNG rel16/32 7+m,3 Jump near if not greater (ZF=1
93 or SF<>OF)
94 0F 8C cw/cd JNGE rel16/32 7+m,3 Jump near if not greater or
95 equal (SF<>OF)
96 0F 8D cw/cd JNL rel16/32 7+m,3 Jump near if not less (SF=OF)
97 0F 8F cw/cd JNLE rel16/32 7+m,3 Jump near if not less or equal
98 (ZF=0 and SF=OF)
99 0F 81 cw/cd JNO rel16/32 7+m,3 Jump near if not overflow (OF=0)
100 0F 8B cw/cd JNP rel16/32 7+m,3 Jump near if not parity (PF=0)
101 0F 89 cw/cd JNS rel16/32 7+m,3 Jump near if not sign (SF=0)
102 0F 85 cw/cd JNZ rel16/32 7+m,3 Jump near if not zero (ZF=0)
103 0F 80 cw/cd JO rel16/32 7+m,3 Jump near if overflow (OF=1)
104 0F 8A cw/cd JP rel16/32 7+m,3 Jump near if parity (PF=1)
105 0F 8A cw/cd JPE rel16/32 7+m,3 Jump near if parity even (PF=1)
106 0F 8B cw/cd JPO rel16/32 7+m,3 Jump near if parity odd (PF=0)
107 0F 88 cw/cd JS rel16/32 7+m,3 Jump near if sign (SF=1)
108 0F 84 cw/cd JZ rel16/32 7+m,3 Jump near if 0 (ZF=1)
109 </PRE>
111 <EM>
112 <H3>Notes</H3>
113 The first clock count is for the true condition (branch taken); the
114 second clock count is for the false condition (branch not taken). rel16/32
115 indicates that these instructions map to two; one with a 16-bit relative
116 displacement, the other with a 32-bit relative displacement, depending on
117 the operand-size attribute of the instruction.
118 </EM>
120 <H2>Operation</H2>
122 <PRE>
123 IF condition
124 THEN
125 EIP := EIP + SignExtend(rel8/16/32);
126 IF OperandSize = 16
127 THEN EIP := EIP AND 0000FFFFH;
130 </PRE>
132 <H2>Description</H2>
134 Conditional jumps (except JCXZ) test the flags which have been set by
135 a previous instruction. The conditions for each mnemonic are given in
136 parentheses after each description above. The terms "less" and "greater"
137 are used for comparisons of signed integers; "above" and "below" are
138 used for unsigned integers.
140 If the given condition is true, a jump is made to the location provided as
141 the operand. Instruction coding is most efficient when the target for the
142 conditional jump is in the current code segment and within -128 to
143 +127 bytes of the next instruction's first byte. The jump can also target
144 -32768 thru +32767 (segment size attribute 16) or -2^(31) thru +2^(31) -1
145 (segment size attribute 32) relative to the next instruction's first byte.
146 When the target for the conditional jump is in a different segment, use
147 the opposite case of the jump instruction (i.e., JE and JNE), and then
148 access the target with an unconditional far jump to the other segment.
149 For example, you cannot code--
150 <PRE>
151 JZ FARLABEL;
152 </PRE>
153 You must instead code--
154 <PRE>
155 JNZ BEYOND;
156 JMP FARLABEL;
157 BEYOND:
158 </PRE>
159 Because there can be several ways to interpret a particular state of the
160 flags, ASM386 provides more than one mnemonic for most of the
161 conditional jump opcodes. For example, if you compared two characters in
162 AX and want to jump if they are equal, use JE; or, if you ANDed AX
163 with a bit field mask and only want to jump if the result is 0, use JZ, a
164 synonym for JE.
166 JCXZ differs from other conditional jumps because it tests the contents of
167 the CX or ECX register for 0, not the flags. JCXZ is useful at the beginning
168 of a conditional loop that terminates with a conditional loop instruction
169 (such as
170 <A HREF="LOOP.htm">LOOPNE</A>
171 TARGET LABEL). The JCXZ prevents entering the loop with CX or
172 ECX equal to zero, which would cause the loop to execute 64K or 32G times
173 instead of zero times.
175 <H2>Flags Affected</H2>
177 None
179 <H2>Protected Mode Exceptions</H2>
181 #GP(0) if the offset jumped to is beyond the limits of the code segment
183 <H2>Real Address Mode Exceptions</H2>
185 None
187 <H2>Virtual 8086 Mode Exceptions</H2>
189 None
193 <HR>
195 <B>up:</B> <A HREF="c17.htm">
196 Chapter 17 -- 80386 Instruction Set</A><BR>
197 <B>prev:</B><A HREF="IRET.htm"> IRET/IRETD Interrupt Return</A><BR>
198 <B>next:</B><A HREF="JMP.htm"> JMP Jump</A>
199 </BODY>