Contents    Page-10    Prev    Next    Page+10    Index   

IF Statement Generation

Code for an intermediate code statement of the form (if c p1 p2) can be generated as follows:

  1. Generate code for the condition c using the arithmetic expression code generator. Note that a cmp instruction should be generated for all comparison operators, regardless of which comparison is used.

  2. Generate the appropriate jump-on-condition instruction, denoted jmp c below, by table lookup depending on the comparison operator.

    jmp c   .L1
    p2             # "else"
    jmp     .L2
.L1:
    p1             # "then"
.L2:

The following jump table can be used:

op = < >
c je jne jl jle jge jg
-c jne je jge jg jl jle