Waitprob1 hello 0 1 bye 2 bye in this case the parent

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: le .L5 movl %edx,%eax loop: result += a a -= b i += b Compare i:255 If <= goto loop Set result as return value D. The equivalent goto code is as follows 1 2 3 4 5 6 7 8 9 10 11 12 int loop_while_goto(int a, int b) { int i = 0; int result = a; loop: result += a; a -= b; i += b; if (i <= 255) goto loop; return result; } Problem 3.12 Solution: [Pg. 127] One way to analyze assembly code is to try to reverse the compilation process and produce C code that would look “natural” to a C programmer. For example, we wouldn’t want any goto statements, since these are seldom used in C. Most likely, we wouldn’t use a do-while statement either. This exercise forces you to reverse the compilation into a particular framework. It requires thinking about the translation of for loops. It also demonstrates an optimization technique known as code motion, where a computation is moved out of a loop when it can be determined that its result will not change within the loop. A. We can see that result must be in register %eax. It gets set to 0 initially and it...
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