CS 212 Section 4 2/18/2002 === If's === BALI: main() int x; x := 7; if ( (x = 5) ) x := 10; else { if ( (x > 5) ) x := 20; else x := 30; } return x; SAM: ADDSP 2 // Adjust sp for rv, x PUSHIMM 7 // Push 7 on the stack STOREOFF 1 // Store 7 for x PUSHOFF 1 // Push the value of x to compare PUSHIMM 5 // Push the value to compare with x EQUAL // Compare x to 5 JUMPC correct // result of equal (0 or 1) PUSHOFF 1 // false: push value of x to compare PUSHIMM 5 // push value to compare with x GREATER // compare x > 5 JUMPC nestedCorrect // result of GREATER (0 or 1) PUSHIMM 30 // false: push 30 STOREOFF 1 // store 30 for x JUMP continue // skip to continue label nestedCorrect: // label for executing x := 20; PUSHIMM 20 // true: push value 20 STOREOFF 1 // store 20 for x JUMP continue // skip to continue label correct: // label for executing x := 10; PUSHIMM 10 // true: push value 10 STOREOFF 1 // Store 10 for x JUMP continue // skip to continue label (redundant code) continue: // label after all the if stmts PUSHOFF 1 // Push the value of x to top of stack STOREOFF 0 // Store the value of x in the rv ADDSP -1 // Adjust sp so program returns rv STOP // stop the program