Rewriting an assembly language program to run on a

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: sh to use the result of some computation multiple times. For example, consider the expression x = (a*b)*(-(a*b)+c). For efficiency, we would like to compute a*b only once, but our stack instructions do not provide a way to keep a value on the stack once it has been used. With the set of instructions listed in Figure 3.29, we would therefore need to store the intermediate result a+b in some memory location, say t, and retrieve this value for each use. This gives the following code: 1 load c %st(0) 7 neg ¡ ´ %st(1) µ %st(0) %st(1) 2 load b %st(0) %st(2) %st(1) 8 addp ¡ ´ µ· %st(0) 3 load a %st(0) 9 ¡ ´ load t ¡ µ· %st(1) %st(0) 4 multp ¡ %st(1) %st(0) 10 multp ¡ ¡ ¡ ´ ´ µ· µ %st(0) 5 storep t %st(0) 11 storep x %st(0) load t This approach has the disadvantage of generating additional memory traffic, even though the register stack has sufficient capacity to hold its intermediate results. The IA32 floating-point unit avoids this inefficiency 6 ¡ %st(1) 3.14. *FLOATING-POINT CODE Instruction flds Ö fldl Ö fldt Ö fildl Ö fld %st( ) Source Format Single double ex...
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