Once the loop exits val is copy to register eax as

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: se tests use combinations of the carry and zero flags. Practice Problem 3.7: In the following C code, we have replaced some of the comparison operators with “__” and omitted the data types in the casts. 1 2 3 4 5 6 7 8 9 10 char ctest(int a, int { char t1 = a char t2 = b char t3 = ( )c char t4 = ( )a char t5 = c char t6 = a return t1 + t2 + t3 } b, int c) __ b; __ ( ) a; __ ( ) a; __ ( ) c; __ b; __ 0; + t4 + t5 + t6; For the original C code, GCC generates the following assembly code 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 movl 8(%ebp),%ecx movl 12(%ebp),%esi cmpl %esi,%ecx setl %al cmpl %ecx,%esi setb -1(%ebp) cmpw %cx,16(%ebp) setge -2(%ebp) movb %cl,%dl cmpb 16(%ebp),%dl setne %bl cmpl %esi,16(%ebp) setg -3(%ebp) testl %ecx,%ecx setg %dl addb -1(%ebp),%al addb -2(%ebp),%al addb %bl,%al addb -3(%ebp),%al addb %dl,%al movsbl %al,%eax Get a Get b Compare Compute Compare Compute Compare Compute a:b t1 b:a t2 c:a t3 Compare a:c Compute t4 Compare c:b Compute t5 Test a Comp...
View Full Document

Ask a homework question - tutors are online