Problem 3.6(P147 In the compilation of the loop for (i=0: i<n; i++) we find t To set register %edx to O, Xor exploiting the program Exp that x^×=0 for any×.It corresponds to the c even operators statement i=0 on n the c program a Tmm eduction implement 2021/10/29 11
Problem 3.6 (P147) In the compilation of the loop for (i = 0; i < n; i++) v += i; we find the following assembly code line: xorl %edx, %edx Explain why this instruction would be there, even though there are no EXCLUSIVE-OR operators in our C code. What operation in the C program does this instruction implement ? 2021/10/29 11 To set register %edx to 0, exploiting the program that x^x =0 for any x. It corresponds to the C statement i = 0
Problem 3.7(P151) In the following c code we have replaced se of the comparison operators with -andom omitted the asts char ctes cmp|%ec×, setl%a cmpl %ecx, %esi setb-1(%ehn char t1= a< cmpw%cX, 16(%ebp) setge-2(%ebp) char t2 b_<(unsigned -movb %cl, %dI char +3=(short )c>=(short)ap char t4 =( char)al=( char )c char t5= char t6=a> O return t1++2+t3+t4++5+t6 2021/10/29
< > > short >= short char != char < unsigned Problem 3.7 (P151) • In the following C code, we have replaced some of the comparison operators with “__” and omitted the data types in the casts. char ctest(in a, int b, int c) { char t1 = a ___ b; char t2 = b ___( ) a; char t3 = ( ) c __ ( )a; char t4 = ( ) a __ ( )c; char t5 = c ____ b; char t6 = a _____ 0; return t1 + t2 + t3 + t4 + t5 + t6 ; } 2021/10/29 12 cmpl %ecx, %esi setl %al cmpl %ecx, %esi setb -1(%ebp) cmpw %cx, 16(%ebp) setge -2(%ebp) movb %cl, %dl