L8 leave ret l7 subl jmp x86 ebp esp ebp 8ebp

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: ) Above (unsigned) Below (unsigned) x86 University of Washington Reading CondiMon Codes (Cont.)   SetX InstrucMons: %eax %ah %al %ecx %ch %cl One of 8 addressable byte registers %edx %dh %dl   Does not alter remaining 3 bytes   Typically use movzbl to finish job %ebx %bh %bl Set single byte to 0 or 1 based on combinaIon of condiIon codes   int gt (int x, int y) { return x > y; } %esi %edi %esp %ebp Body: y at 12(%ebp), x at 8(%ebp) movl 12(%ebp),%eax cmpl %eax,8(%ebp) setg %al movzbl %al,%eax # eax = y # Compareoes each of What d x : y #these instrucMons do? al = x > y # Zero rest of %eax x86 University of Washington Reading CondiMon Codes (Cont.)   SetX InstrucMons: %eax %ah %al %ecx %ch %cl One of 8 addressable byte registers %edx %dh %dl   Does not alter remaining 3 bytes   Typically use movzbl to finish job %ebx %bh %bl Set single byte to 0 or 1 based on combinaIon of condiIon codes   int gt (int x, int y) { return x > y; } %esi %edi %esp %ebp Body: y at 12(%ebp), x at 8(%ebp) movl 12(%ebp),%eax cmpl %eax,8(%ebp) setg %al movzbl %al,%eax # # # # eax = y Compare x and y al = x > y Zero rest of %eax x86 (x – y) University of Washington CondiMonal Branch Example int absdiff(int x, int y) { int result; if (x > y) { result = x-y; } else { result = y-x; } return result; } absdiff: pushl movl movl movl cmpl jle subl movl .L8: leave ret .L7: subl jmp x86 %ebp %esp, %ebp 8(%ebp), %edx 12(%ebp), %eax %eax, %edx .L7 %eax, %edx %edx, %eax Setup Body1 Finish %edx, %eax .L8 Body2 University of Washington CondiMonal Branch Example (Cont.) int goto_ad(int x, int y) { int result; if (x <= y) goto Else; result = x-y; Exit: return result; Else: result = y-x; goto Exit; } int absdiff(int x, int y) { int result; if (x > y) { result = x-y; } else { result = y-x; } return result; }     x86 C allows “goto” as means of transferring control   Closer to machine ­level programming style Generally considered bad coding style University of Washington CondiM...
View Full Document

Ask a homework question - tutors are online