next up previous contents
Next: Boolean Operators Up: Binary Operators Previous: Arithmetic operators

Comparison Operators

To compare two values of type integer, boolean or char, the following code is used:

 
 if_icmp<cond> 7			 If comparison succeeds jump 7 bytes (skip 2
			   	   instructions);

iconst_0 not succeeded, so push a 0;

goto 4 jump 4 bytes (skip next instruction);

iconst_1 succeeded, so push a 1.

The if_icmp<cond> instruction is one of the instructions if_icmplt, if_icmple, if_icmpgt, if_icmpge, if_icmpeq and if_icmpne for respectively the Pascal operations ` <', ` <=', ` >', ` >=', ` =' and ` <>'.

If the two values of the comparison operation are of type real they have to be compared by the fcmpg instruction first and the resulting value is compared to zero. The fcmpg instruction pushes the value -1 on the stack when the first value is less than the second value, it pushes the value 0 on the stack when they are equal and it pushes the value 1 on the stack when the first value is greater than the second value. The code is:

 
 fcmpg				 Compare the two float values;

if<cond> 7 If comparison to zero succeeds jump 7 bytes (skip 2 instructions);

iconst_0 not succeeded, so push a 0;

goto 4 jump 4 bytes (skip next instruction);

iconst_1 succeeded, so push a 1.

The <cond> of the if<cond> instruction is the same as the if_icmp<cond> instruction.



mark@bottom.xs4all.nl