null i printf envp2d sn i envpi exit0

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: is left in %eax at the end of the loop as a return value. We can see that i is held in register %edx, since this register is used as the basis for two conditional tests. B. The instructions on lines 2 and 4 set %edx to n-1. C. The tests on lines 5 and 12 require i to be nonnegative. D. Variable i gets decremented by instruction 4. E. Instructions 1, 6, and 7 cause x*y to be stored in register %edx. F. Here is the original code: 706 1 2 3 4 5 6 7 8 9 APPENDIX B. SOLUTIONS TO PRACTICE PROBLEMS int loop(int x, int y, int n) { int result = 0; int i; for (i = n-1; i >= 0; i = i-x) { result += y * x; } return result; } Problem 3.13 Solution: [Pg. 131] This problem gives you a chance to reason about the control flow of a switch statement. Answering the questions requires you to combine information from several places in the assembly code: 1. Line 2 of the assembly code adds 2 to x to set the lower range of the cases to 0. That means that the minimum case label is ¾. 2. Lines 3 and 4 cause the program to jump to the default case when the adjusted case value is greater than 6. This implies tha...
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