![]() | ![]() | ![]() | Generating Code for REAL Control Structures |
if x <> 0 then if y <> 0 then stmt 1 else stmt 2 else stmt 3
CMP #0,x BEQ label3 CMP #0,y BEQ label5 <code for stmt 1> JMP label6 label5 <code for stmt 2> label6 JMP label4 label3 <code for stmt 3> label4
gen_if(node * ifstmt, codelabel *nextlabel) { codelabel lab1; oprnd_desc *result; genlabel(&lab1); gencondexpr( ifstmt->internal.child[0] FALSE, &lab1 ); gen_stmt(ifstmt->internal.child[1], nextlabel); output `JMP nextlabel' place_label(&lab1); gen_stmt(ifstmt->internal.child[2], nextlabel); }
CMP #0,x BEQ label3 CMP #0,y BEQ label5 <code for stmt 1> JMP label4 label5 <code for stmt 2> JMP label4 label3 <code for stmt 3> label4
Then again, it may find out that it was called for an assignment statement and not use "nextlabel" at all.
Beware that the label placed at the start of a while loop body will not be used until after it has been "placed".
![]() | ![]() | ![]() | Generating Code for REAL Control Structures |