This preview shows page 1. Sign up to view the full content.
Unformatted text preview: division has precedence over subtraction, this expression can be parenthesized as x = a-(b/c). The recursive procedure would therefore proceed as follows: 1. Generate code for ÜÔÖ a-(b/c): b/c: (a) Generate code for ÜÔÖ ¾ i. Generate code for ÜÔÖ ¾ c using the instruction load c. ii. Generate code for ÜÔÖ ½ b, using the instruction load b. iii. Generate instruction divp. (b) Generate code for ÜÔÖ ½ (c) Generate instruction subp. a, using the instruction load a. 178 CHAPTER 3. MACHINE-LEVEL REPRESENTATION OF C PROGRAMS 2. Generate instruction storep x. The overall effect is to generate the following stack code:
%st(1) 1 load c %st(0) 4 load a %st(0) %st(1) 2 load b %st(0) 5 subp ´ µ %st(0) 3 divp Practice Problem 3.25: %st(0) 6 storep x Generate stack code for the expression x = a*b/c * -(a+b*c). Diagram the contents of the stack for each step of your code. Remember to follow the C rules for precedence and associativity. Stack evaluation becomes more complex when we wi...
View Full Document
- Spring '10
- The American