Chapter 7 · SimulationConditional Jumps ? ← Chapter 7 ◀ Step ▶ Play To end Reset Close Conditional Jumps Goal: see how each conditional jump decides from the flags set by CMP a, b, and why the signed (G/L) and unsigned (A/B) families can give different results for the same bits; and follow how CX and the flags change in small loops. How to use it CMP + Jcc: type a and b in hexadecimal (0FBh), binary (1010b) or decimal (-5). Step ▶ (or →) reveals first the flags, then the jumps one by one; the row shows the condition together with the flags it looks at. Loop: choose a program, set the start value and run the instructions step by step. The registers and flags appear on the right, the last steps below. Try it yourself: for each jump you are first asked to guess “jumps” or “does not jump”. Rules CMP a, b computes a − b and does not store the result; it only sets CF, ZF, SF, OF, PF, AF. Unsigned: JA (CF = 0 and ZF = 0), JAE = JNB = JNC (CF = 0), JB = JNAE = JC (CF = 1), JBE (CF = 1 or ZF = 1). Signed: JG (ZF = 0 and SF = OF), JGE (SF = OF), JL (SF ≠ OF), JLE (ZF = 1 or SF ≠ OF). On overflow SF shows the opposite of the true sign of the result; that is why SF and OF are evaluated together. LOOP first decrements CX by 1, jumps if CX ≠ 0, and does not change the flags. DEC CX + JNZ does the same job but changes ZF, SF, OF, PF, AF (CF is kept). If LOOP is entered with CX = 0, CX becomes FFFFh and the body runs 65,536 times. On the 8086 conditional jumps are 2 bytes long and can reach only −128…+127 bytes. The flag and jump results and the loop traces were checked against an 8086 interpreter. Related slides: Chapter 7 · Flow Control (Jumps That Test a Single Flag, The CMP Instruction, Jumps for Signed and Unsigned Numbers, Why SF = OF?, Loop Instructions).