lec8_jumps - Carnegie Mellon Carnegie Mellon Assembly...

Info icon This preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon
1 Carnegie Mellon Assembly: Control through Jumps Marco Gruteser 331 Computer Architecture and Assembly Language Carnegie Mellon Slides adapted from Bryant, O’Hallaron, and Nath.
Image of page 1

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

View Full Document Right Arrow Icon
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 significant bit (used for unsigned comparisons) §੿ ZF set if a == b §੿ SF set if (a-b) < 0 (as signed) §੿ OF set if two’s-­૒complement (signed) overflow (a>0 && b<0 && (a-b)<0) || (a<0 && b>0 && (a-b)>0)
Image of page 2
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
Image of page 3

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

View Full Document Right Arrow Icon
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)
Image of page 4
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 finish 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
Image of page 5

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

View Full Document Right Arrow Icon
6 Carnegie Mellon Reading Condi6on Codes: x86-­૒64 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 0! cmpq %rsi, %rdi setg %al movzbl %al, %eax
Image of page 6
7 Carnegie Mellon Today ¢ਯ Complete addressing mode, address computa6on (leal) ¢ਯ Arithme6c opera6ons ¢ਯ x86-­૒64 ¢ਯ Control: Condi6on codes ¢ਯ Condi6onal branches & Moves ¢ਯ Loops
Image of page 7

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

View Full Document Right Arrow Icon
8 Carnegie Mellon Jumping ¢ਯ jX Instruc6ons §੿
Image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern