Lecture3-ia32-control

Lecture3-ia32-contro - Announcements CS 3214 Computer Systems Systems Lecture 3 Godmar Back Exercise 1 due Aug 30 Stay tuned for exercise 2 Project

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

View Full Document Right Arrow Icon
1 CS 3214 Computer Systems Godmar Back Lecture 3 Announcements • Exercise 1 due Aug 30 • Stay tuned for exercise 2 • Project 1 due Sep 7 • Should have teamed up now Should now have access to systems lab (McB 124) via Should now have access to systems lab (McB 124) via keycard – Has Unix workstations for you to use – Send email to me if it doesn’t work • Make sure you’re on piazza CS 3214 Fall 2011 The following slides are taken with permission from Complete Powerpoint Lecture Notes for Computer Systems: A Programmer's Perspective 2 nd Edition (CS:APP 2e) Randal E. Bryant and David R. O'Hallaron http://csapp.cs.cmu.edu/public/instructors.html PROGRAMS AND DATA Part 2 CS 3214 Fall 2011 Condition Codes • Single Bit Registers CF Carry Flag SF Sign Flag ZF Zero Flag OF Overflow Flag • Implicitly Set By Arithmetic Operations addl Src , Dest C analog: t = a + b –CF set if carry out from most significant bit • Used to detect unsigned overflow –ZF set if t == 0 –SF set if t < 0 –OF set if two’s complement overflow (a>0 && b>0 && t<0) || (a<0 && b<0 && t>=0) Not Set by leal instruction CS 3214 Fall 2011 Setting Condition Codes (cont.) Explicit Setting by Compare Instruction cmpl Src2 , Src1 cmpl b,a like computing a-b without setting destination – CF set if carry out from most significant bit • Used for unsigned comparisons – ZF set if a == b – SF set if (a-b) < 0 – OF set if two’s complement overflow (a>0 && b<0 && (a-b)<0) || (a<0 && b>0 && (a-b)>0) CS 3214 Fall 2011 Setting Condition Codes (cont.) • Explicit Setting by Test instruction testl Src2 , Src1 – Sets condition codes based on value of Src1 & Src2 • Useful to have one of the operands be a mask testl b,a like computing a&b without setting destination – ZF set when a&b == 0 – SF set when a&b < 0 CS 3214 Fall 2011
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 Reading Condition Codes SetX Condition Description sete ZF Equal / Zero setne ~ZF Not Equal / Not Zero sets SF Negative setns SF Nt i • setX Instructions – Set single byte based on combinations of condition codes setns ~SF Nonnegative 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) CS 3214 Fall 2011 Reading Condition Codes (Cont.) • setX Instructions – Set single byte based on combinations of condition codes – One of 8 addressable byte registers • Embedded within first 4 integer registers • Does not alter remaining 3 bytes • Typically use movzbl to finish job %eax %edx %ecx %ebx %al %ah %dl %dh %cl %ch %bl %bh %esi %edi %esp %ebp int gt (int x, int y) { return x > y; } 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 Note inverted ordering! Body CS 3214 Fall 2011 Jumping jX Condition Description jmp 1 Unconditional je ZF Equal / Zero jne ~ZF Not Equal / Not Zero js SF Negative j SF • jX Instructions – Jump to different part of code depending on condition codes jns ~SF Nonnegative jg ~(SF^OF)&~ZF Greater (Signed) jge ~(SF^OF) Greater or Equal (Signed) jl (SF^OF) Less (Signed) jle (SF^OF)|ZF Less or Equal (Signed) ja ~CF&~ZF
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 12/31/2011 for the course CS 3214 taught by Professor Staff during the Fall '11 term at Virginia Tech.

Page1 / 7

Lecture3-ia32-contro - Announcements CS 3214 Computer Systems Systems Lecture 3 Godmar Back Exercise 1 due Aug 30 Stay tuned for exercise 2 Project

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

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