
Project: Compiler for a MiniC 369
The corresponding raw assembly code generator function – efgt() – looks like
efgt(){
emit(" fcomip %%st(1)\n",0); // want "st(1) > st(0)?"
emit(" setc %%al\n",0); // i.e. TOS < st(1)
emit(" andl $1, %%eax\n",0); // 1st 2nd
emit(" fstp FPacc\n",0);
}
The floating point compares the instruction sets two flags C and Z. We set al to 1 if the C is set, i.e.
TOS is less than the second operand. Remember we want to check if al is 0 or 1, which is achieved
by the andl instruction. This will set up the flags again for a subsequent JZ instruction.
Other comparisons are implemented in similar ways.
12.8.4