1 a movl 3 ebx l e a l ebxebx 2 ebx ebx9 b movl 0x123 ebx s h r l 8 ebx l e a l

1 a movl 3 ebx l e a l ebxebx 2 ebx ebx9 b movl 0x123

This preview shows page 1 - 4 out of 5 pages.

1
Image of page 1
(a) movl $3 , %ebx l e a l (%ebx,%ebx , 2 ) , %ebx %ebx=9 (b) movl $0x123 , %ebx s h r l $8 , %ebx l e a l 1(%ebx,%ebx , 4 ) , %ebx %ebx=6 (c) xorl %ebx,%ebx l e a l 1(%ebx ) , %ebx s a l l $3 , %ebx l e a l 2(%ebx,%ebx , 8 ) , %ebx %ebx=74 4. Consider the following C program #include < stdio . h > int p ( int a , int b , int c ) { int d , e , f ; f = 0; for (d=a ; d < b ; d++) for ( e=b ; e < c ; e++) f += d + e ; return f ; } When compiled with a high level of optimization, it looks like this (with line numbers added for reference): 01 p : 02 pushl %ebp 03 movl %esp , %ebp 04 pushl %edi 05 pushl %e s i 06 movl 12(%ebp ) , %edi 07 movl 8(%ebp ) , %ecx 08 pushl %ebx 09 xorl %ebx , %ebx 10 cmpl %edi , %ecx 11 movl 16(%ebp ) , %e s i 12 jge . L28 13 . L26 : 14 cmpl %esi , %edi 2
Image of page 2
15 movl %edi , %edx 16 jge . L30 17 . L25 : 18 l e a l (%edx,%ecx ) , %eax 19 i n c l %edx 20 addl %eax , %ebx 21 cmpl %esi , %edx 22 j l . L25 23 . L30 : 24 i n c l %ecx 25 cmpl %edi , %ecx 26 j l . L26 27 . L28 : 28 movl %ebx , %eax 29 popl %ebx 30 popl %e s i 31 popl %edi 32 movl %ebp,%esp 33 popl %ebp 34 ret (a) Write the name of the register and the offset from %ebp corresponding to each of a, b, and c. a is %ecx and offset 8 from %ebp. b is %edi and offset 12 from %ebp. c is %esi and offset 16 from %ebp. (b) Write the name of the register corresponding to each one of d,e, f, and the return value. d is %ecx (the register for a is re-used for d). e is %edx. f is %ebx. (c) Which line number corresponds to d = a;? Line 7 assigns the a parameter from the frame to the register allocated for d. (d) Which line number is the last of the assembly statements that implements f += d + e;? Line 20. (e) If line 32 were removed, would the function still work properly? Why or why not? Yes. At this point in the code, everything that has been pushed since %ebp was pushed on line 2 has also
Image of page 3
Image of page 4

You've reached the end of your free preview.

Want to read all 5 pages?

  • Fall '08
  • Staff

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes