Introduction to Computer Organization and Assembly Language

Report
Introduction to Computer
Organization and Assembly
Language
Sheet 3
By: Nora Alaqeel
The FLAGS Register - Status Flags
• Carry Flag (CF):
• CF = 1 if there is a carry out from the msb on addition.
• CF = 1 if there is a borrow into the msb on subtraction.
• CF = 0 otherwise.
• CF is also affected by shift and rotate instructions.
• Parity Flag (PF):
• PF = 1 if the low byte of a result has an even number of one bits
• PF = 0 if the low byte has odd parity
(ex. if a result is FFFE
PF = 0).
By: Nora Alaqeel
The FLAGS Register - Status Flags
•
Zero Flag (ZF):
• ZF = 1 for a zero result.
• ZF = 0 for nonzero result.
• Sign Flag (SF):
• SF = 1 if the msb of a result is 1.
(i.e. Negative if signed interpretation is used).
• SF = 0 if the msb is 0.
By: Nora Alaqeel
The FLAGS Register - Status Flags
• Overflow Flag (OF):
• OF = 1 if signed overflow occurred.
• OF = 0 otherwise.
By: Nora Alaqeel
How Instructions Affect the Flags
• In general, each time the processor executes an instruction, the flags
are altered to reflect the result.
• However, some instructions don’t affect any of the flags, affects
only some of them, or may leave them undefined.
Instruction
MOV/XCHG
ADD/SUB
INC/DEC
By: Nora Alaqeel
Affects flags
none
all
all except CF
Question 1
Q1: For each of the following instructions,
give the new destination contents and the
new settings of SF,ZF,PF, CF and OF.
Suppose that the flags are initially 0 in each
part of this question:
By: Nora Alaqeel
Question 1
 a. ADD AX, BX ;AX= 4034h, BX=8051h
4034
8051
0100 0000 0011 0100
1000 0000 0101 0001
C085
1100 0000 1000 0101
SF=1 , ZF=0 , PF=0 , CF=0 , OF=0
By: Nora Alaqeel
Question 1
 b. NEG AX ;AX= 6431h
FFFF
6431
9BCE
1
9BCF
1001 1011 1100 1111
SF=1 , ZF=0 , PF=1 , CF=1 , OF=0
By: Nora Alaqeel
Question 1
 c. SUB AL, BL ;AL= 34h, BL=51h
34
51
0011 0100
0101 0001
E3
1110 0011
SF=1 , ZF=0 , PF=0 , CF=1 , OF=0
By: Nora Alaqeel
Question 1
 d. DEC BL ;BL=01h
01
1
0000 0001
0000 0001
00
0000 0000
SF=0 , ZF=1 , PF=1 , CF=not effected ,
OF=0
By: Nora Alaqeel
Question 2
 Q2: Write a program to do the following:
The program should prompts the user to enter an
uppercase letter, then display that letter in lowercase
at the same line.
 Sample Execution:
ENTER UPPER CASE LETTER: Aa
By: Nora Alaqeel
Question 2
By: Nora Alaqeel
Question 2
By: Nora Alaqeel
Question 2
By: Nora Alaqeel
Question 2
By: Nora Alaqeel

similar documents