"Use of GoBug" demonstrations
Conditional jump & use of flags tests

These tests demonstrate GoBug's pane display when using the conditional jump mnemonics and also how the various flags are used. The test is also a good demonstration of single-stepping.
See also Effect on flags to see how various instructions effect the flags.

To view these tests, start Testbug as the debuggee, and set the breakpoint CONDITIONAL_JUMPS using GoBug's "action, run to .. procedure" menu item. Then use Testbug's menu to run the test.

The tests are mostly carried out using the CMP mnemonic with the register values set by the program, but of course you can change the register values to see how this affects the results. To do this click on the register you want to change (enter when finished, escape to cancel). You can also change the flags themselves, which demonstrates some of the more obscure conditional jump tests.
Here is how the conditional flags work:-
JZ - jump if zero flag is set
JP - jump if parity flag is set
JC - jump if carry flag is set
JB - jump if "below" - carry flag is set (same as JC)
JA - jump if "above" - neither carry flag nor zero is set
JCXZ - jump if CX is zero
JECXZ - jump if ECX is zero
and for testing the result when regarding numbers as "signed":-
JO - jump if overflow is set
JS - jump if sign flag is set
JL - jump if "less" - sign and overflow flags not the same state
JG - jump if "greater" - sign=overflow flag & zero flag is clear

The "N" versions of these mnemonics are the reverse of the above. Note that JA (jump if above) does not test the "A" flag, which is used to give the result in some BCD arithmetic.

The tests are all in one block, but they are in 3 parts:-
short jumps and use of flags (dword registers)
short jumps and use of flags (byte registers)
short and long jumps forward and back
Each individual test is separated by an "NOP" mnemonic (opcode 90) which does nothing, and is used to separate the individual tests to make a short forward jump to the next test more obvious.
The shortest mnemonic is used eg. JA, which is the same as JNBE, JP which is the same as JPE etc.

Short jumps and use of flags (dword registers)
The conditional jump and flag tests are contained in SHORTJUMP_TEST1 which is called 9 times, using various values in EAX and EDX, so that the effect on the flags can be seen. If you are not interested in these tests you can just jump over them using F6. When you carry out the tests watch the register values and how they change.
If you want to see how the JL and JG jumps work, pay particular attention to the tests when EAX and EDX are set to -1 (0FFFFFFFFh) and 1 respectively or the other way round. JL and JG regard the values in the registers as signed numbers, and therefore use the overflow rather than the carry flag to decide whether to jump. Using these instructions, 1 will be regarded as greater than -1 and JG will jump. -1 will be regarded as less than 1 and JL will jump. JB and JA give a different result because (when regarded as unsigned numbers) 1 is below -1 and -1 is above 1.

Short jumps and use of flags (byte registers)
With AL=14h and DL=10h this shows the effect of various conditional jump tests.

Short and long jumps forward and back
These tests demonstrate the backwards jump, short jumps to start with then long ones