lec8_jumps

lec8_jumps - 1 Carnegie Mellon Assembly: Control through...

Info iconThis preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 1 Carnegie Mellon Assembly: Control through Jumps Marco Gruteser 331 Computer Architecture and Assembly Language Carnegie Mellon Slides adapted from Bryant, OHallaron, and Nath. 2 Carnegie Mellon Condi6on Codes (Explicit Se<ng: Compare) Explicit Se<ng by Compare Instruc6on cmpl/cmpq Src2, Src1 cmpl b,a like compu0ng a-b without se7ng des0na0on CF set if carry out from most signicant bit (used for unsigned comparisons) ZF set if a == b SF set if (a-b) < 0 (as signed) OF set if twos-complement (signed) overow (a>0 && b<0 && (a-b)<0) || (a<0 && b>0 && (a-b)>0) 3 Carnegie Mellon Condi6on Codes (Explicit Se<ng: Test) Explicit Se<ng by Test instruc6on testl / testq Src2, Src1 testl b,a like compu0ng a&b without se7ng des0na0on Sets condi0on codes based on value of Src1 & Src2 Useful to have one of the operands be a mask ZF set when a&b == 0 SF set when a&b < 0 4 Carnegie Mellon Reading Condi6on Codes SetX Instruc6ons Set single byte based on combina0ons of condi0on codes SetX Condi0on Descrip0on sete ZF Equal / Zero setne ~ZF Not Equal / Not Zero sets SF Nega0ve setns ~SF Nonnega0ve setg ~(SF^OF)&~ZF Greater (Signed) setge ~(SF^OF) Greater or Equal (Signed) setl (SF^OF) Less (Signed) setle (SF^OF)|ZF Less or Equal (Signed) seta ~CF&~ZF Above (unsigned) setb CF Below (unsigned) 5 movl 12(%ebp),%eax # eax = y cmpl %eax,8(%ebp) # Compare x : y setg %al # al = x > y movzbl %al,%eax # Zero rest of %eax Carnegie Mellon Reading Condi6on Codes (Cont.) SetX Instruc6ons: Set single byte based on combina0on of condi0on codes One of 8 addressable byte registers Does not alter remaining 3 bytes Typically use movzbl to Fnish job int gt (int x, int y) { return x > y; } Body %eax %ah %al %ecx %ch %cl %edx %dh %dl %ebx %bh %bl %esi %edi %esp %ebp 6 Carnegie Mellon Reading Condi6on Codes: x8-4 int gt (long x, long y) { return x > y; } cmpl %esi, %edi setg %al movzbl %al, %eax Bodies long lgt (long x, long y) { return x > y; } SetX Instruc6ons: Set single byte based on combina0on of condi0on codes Does not alter remaining 3 bytes Is %rax zero? Yes: 32-bit instruc0ons set high order 32 bits to ! cmpq %rsi, %rdi setg %al 6 Carnegie Mellon Reading Condi6on Codes: x8-4 int gt (long x, long y) { return x > y; } cmpl %esi, %edi setg %al movzbl %al, %eax Bodies long lgt (long x, long y) { return x > y; } SetX Instruc6ons: Set single byte based on combina0on of condi0on codes Does not alter remaining 3 bytes Is %rax zero?...
View Full Document

Page1 / 31

lec8_jumps - 1 Carnegie Mellon Assembly: Control through...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online