324_Book

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 8 divp ´ · µ´ · µ %st(0) 4 addp %st(0) 9 storep x · %st(1) %st(0) load b As this example shows, there is a natural recursive procedure for converting an arithmetic expression into stack code. Our expression notation has four types of expressions having the following translation rules: 5 1. A variable reference of the form Î Ö . This is implemented with the instruction load Î Ö . 2. A unary operation of the form - ÜÔÖ . This is implemented by first generating the code for followed by a neg instruction. ÜÔÖ 3. A binary operation of the form ÜÔÖ ½ + ÜÔÖ ¾ , ÜÔÖ ½ - ÜÔÖ ¾ , ÜÔÖ ½ * ÜÔÖ ¾ , or ÜÔÖ ½ / ÜÔÖ ¾ . This is implemented by generating the code for ÜÔÖ ¾ , followed by the code for ÜÔÖ ½ , followed by an addp, subp, multp, or divp instruction. 4. An assignment of the form Î Ö = ÜÔÖ . This is implemented by first generating the code for ÜÔÖ , followed by the storep Î Ö instruction. As an example, consider the expression x = a-b/c. Since...
View Full Document

This note was uploaded on 09/02/2010 for the course ELECTRICAL 360 taught by Professor Schultz during the Spring '10 term at BYU.

Ask a homework question - tutors are online