If main terminates with a call to exit then exit

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: on line 7 in the C code. In the assembly code, it is implemented by the instructions on lines 9 to 14 as well as the branch condition on line 15. C. The annotated code is as follows. Initially x, y, and n are at offsets 8, 12, and 16 from %ebp movl 8(%ebp),%esi Put x in %esi movl 12(%ebp),%ebx Put y in %ebx movl 16(%ebp),%ecx Put n in %ecx 1 2 3 704 4 5 6 7 8 9 10 11 12 13 14 15 APPENDIX B. SOLUTIONS TO PRACTICE PROBLEMS .p2align 4,,7 .L6: imull %ecx,%ebx addl %ecx,%esi decl %ecx testl %ecx,%ecx setg %al cmpl %ecx,%ebx setl %dl andl %edx,%eax testb $1,%al jne .L6 loop: y *= n x += n n-Test n n>0 Compare y:n y<n (n > 0) & (y < n) Test least significant bit If != 0, goto loop Note the somewhat strange implementation of the test expression. Apparently, the compiler recognizes that the two predicates (n > 0) and (y < n) can only evaluate to 0 or 1, and hence the branch condition need only test the least significant byte of their AND. The compiler could have been more clever and use...
View Full Document

Ask a homework question - tutors are online