w6-part2-four - 1 1 Machine-Level Programming II: Control...

Info iconThis preview shows pages 1–3. 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
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 1 1 Machine-Level Programming II: Control Flow z Topics z Condition Codes z Setting z Testing z Control Flow z If-then-else z Varieties of Loops 2 Assembly programmer view z ALU: Arithmetic Logic Unit z IR: Instruction register z GPR: General Purpose Registers z PC: Program Counter z SP: Stack Pointer z BR: Base Register ALU GPR Status Flags SP PC Memory Object Code Instructions & Data IR BR 3 Status flags z There are 1 bit flags or condition codes that are set in a status register z ZF stands for zero flag z SF stands for sign flag z CF stands for carry flag (when carry out occurs) z OF stands for overflow flag (when carry in to MSB occurs) z PF parity flag z AF auxiliary flag 4 Status flags (ZF or zero flag) z Status flags or condition codes are set when the processor executes Airthmetic operations z ZF: Zero Flag is set to 1 if an operation results in a zero z Example 1 z mov 0xF %eax z add 1 %eax z Example 2 z Mov 1 %eax z Dec %eax (decrements register by 1) z Operations that set zero flag are: z cmp, inc, dec, sub, add etc 2 5 cmp operation z cmp Src, Dst z Compares by subtracting Dst from Src z cmp op1, op2 z Compares two operands by subtracting op2 from op1 (op2-op1) z Sets the status flags based on the result z Does not alter op2 z Subtract operation or sub instruction stores the result in op2 z sub Src, Dst z Dst Dst- Src z sub op1, op2 op2-op1 result stored in op2 z move $5 %eax z cmp $5 %eax z %eax will still contain 5 but ZF will be set to 1 z move $5 %eax z sub $5 %eax z %eax will have 0 and ZF is set to 1 6 SF (Sign Flag) z As a result of arithmetic operation, the copy of the sign bit is in SF z mov $5 %eax z sub $6 %eax z SF is set to 1 z If the number is positive, MSB is 0 then SF is set to 0 z mov $15 %eax z add $10 %eax z SF is set to 0 7 Carry flag (CF) z CF is set when a carry out occurs z mov ffff,%eax z add 0001, %eax z Unsigned numbers z For 8 bits the range is 0 to 255 z For 16 bits the range is 0 to 65, 535 z For 32 bits the range is 32 bits 0 to 4, 294, 967, 295 z Result of an operation on unsigned numbers result in an overflow z mov $5, %eax z sub $6 %eax z also sets CF operation generates a borrow into MSB z Number is too small to be represented using signed numbers 8 Overflow flag (OF) z When a carry in occurs z When signed numbers get out of range z mov 7200H %eax z add 0E00H %eax z MSB in %eax will be 1 , a carry in has occurred z When you add two unsigned numbers, MSB will be 1 if the result is out...
View Full Document

This note was uploaded on 03/24/2011 for the course CS 211 taught by Professor Chakraborty during the Spring '08 term at Rutgers.

Page1 / 8

w6-part2-four - 1 1 Machine-Level Programming II: Control...

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