solution manual to COMPUTER ORGANIZATION AND ASSEMBLY LANGUAGE CHAPTER 5.
If you find any mistake in the manual please share with me ... it will be appreciated
Chapter 5The proessor status and the FLAGS registers
1. A solution manual to
Assembly language
Programming
and the organization of
the IBM PC
Chapter 5
The processor status and the FLAGS
register
BY:- Ytha Yu & Charles Marut
prepared by :
Warda Aziz
Wardaaziz555@gmail.com
2. Question1:
For each of the following instructions, give the new destination
contents and the new settings of CF,SF,ZF,PF and OF. Suppose that
the flags are initially 0 in each part of this question.
A) ADD AX,BX ;AX=7FFFh and BX=0001h
B) SUB AL, BL ;AL=01h and BL=FFh
C) DEC AL ;AL=00h
D) NEG AL ;AL=7Fh
E) XCHG AX, BX ;AX=1ABCh, BX= 712Ah
F) ADD AL, BL ;AL=80h, BL=FFh
G) SUB AX, BX ; AX=0000h, BX= 8000h
H) NEG AX AX=0001h
ADD AX,BX ;AX=7FFFh and BX=0001h
7=0111 , F=1111
0111 1111 1111 1111
+0000 0000 0000 0001
1000 0000 0000 0000
AL=8000h
CF=0 (No carry out)
SF=1
ZF=0
PF=1
OF=1 (Carry in but no carry out)
SUB AL, BL ;AL=01h and BL=FFh
0000 0001
-1111 1111
0000 0010
AL=02h
CF=1 (borrow into MSB)
SF=0
ZF=0
PF=0
OF=0 (Borrow in and borrow out)
DEC AL ;AL=00h
0000 0000
-1
1111 1111
AL=FFh
CF=no effect(increment/decrement do not effect CF)
SF=1
ZF=0
3. PF=1
OF=0 (Borrow in and borrow out)
NEG AL ;AL=7Fh
7=0111, F=1111
1’s compliment= 1000 0000
1000 0000
+1
1000 0001
AL=81h
CF=1(result is not zero)
SF=1
ZF=0
PF=1
OF=0
XCHG AX, BX ;AX=1ABCh, BX= 712Ah
AX=712Ah
BX=1ABCh
No effect at any flag
ADD AL, BL ;AL=80h, BL=FFh
1000 0000
+1111 1111
10111 1111
AL=17Fh
CF=1
SF=0
ZF=0
PF=0
OF=1
SUB AX, BX ; AX=0000h, BX= 8000h
0000 0000 0000 0000
-1000 0000 0000 0000
1000 0000 0000 0000
AX=8000h
CF=1
SF=1
ZF=0
PF=1
OF=1(borrow in but not borrow out)
NEG AX AX=0001h
0000 0000 0000 0001
1’s compliment=1111 1111 1111 1110
1111 1111 1111 1110
+1
1111 1111 1111 1111
4. AX=FFFFh
CF=1(result is not 0)
SF=1
ZF=0
PF=1
OF=0
Question 2:
a) Suppose that AX and BX both contains +ive numbers, and ADD
AX, BX is executed , show that there is carry into the MSB but no
carry out of the MSB if and only if, signed overflow occurs.
Solution:
As we know signed overflow occurs if and if:
There is a carry into the MSB but no carry out of the MSB.(for addition)
There is a carry out of the MSB but no carry into the MSB.(for addition)
There is a borrow into the MSB but no borrow into the MSB.(for subtraction)
There is a borrow out of the MSB but no borrow into the MSB.(for
subtraction)
So;
For the proof you can see question 3 part a and d. Here signed flow is occurred
because of a carry into the MSB but no carry out of the MSB.
Also in part e where there is no carry out and no carry in; no signed overflow
occurred.
b) Suppose that AX and BX both contains -ive numbers, and ADD
AX, BX is executed , show that there is carry out of the MSB but no
carry into the MSB if and only if, signed overflow occurs.
Solution:
Let’s take an example 8Fh+C9 ;
1000 1111
+1100 1001
1 0101 1000
We can see there is a carry out of the MSB but no carry into the MSB and a
signed overflow occurred.
Remember:
Whenever there is ‘but’ in carry of MSB or borrow of MSB there is a signed
overflow. And
Whenever there is an ‘and’ in carry of MSB or borrow of MSB there is no signed
overflow.
Question 3:
Suppose ADD AX,BX is executed. In each of the following parts,
the first number being added is the content of AX, and the second
number is the contents of BX. Give the resulting value of AX and tell
whether signed or unsigned overflow occurred.
a) 512Ch + 4185h
b) FE12h + 1ACBh
c) E1E4h + DAB3h
5. d) 7132h + 7000h
e) 6389h + 1176h
512Ch + 4185h
0101 0001 0010 1100
+ 0100 0001 1000 0101
1001 0010 1011 0001
AX=92B1
Flow Set/clear reason
Signed 1 Carry in but no carry out
unsigned 0 CF=0
FE12h + 1ACBh
FE12= 1111 1110 0001 0010
+1ACB= 0001 1010 1100 1011
118DD= 1 0001 1000 1101 1101
AX=118DDh
Flow Set/clear reason
Signed 0 carry in and carry out
unsigned 1 CF=1
E1E4h + DAB3h
E1E4= 1110 0001 1110 0100
+ DAB3=1101 1010 1011 0011
1BC97 11011 1100 1001 0111
AX=BC97h ;1 will be in CF
Flow Set/clear reason
Signed 0 carry in and borrow out
unsigned 1 CF=1
7132h + 7000h
7132h= 0111 0001 0011 0010
+7000h= 0111 0000 0000 0000
E132= 1110 0001 0011 0010
Flow Set/clear reason
Signed 1 carry in but no carry out
unsigned 0 CF=0
6389h + 1176h
6389h= 0110 0011 1000 1001
+1176h= 0001 0001 0111 0110
74FF= 0111 0100 1111 1111
Flow Set/clear reason
Signed 0 No carry in, no carry out
6. unsigned 0 CF=0
Question 4:
Suppose SUB AX,BX is executed. In each of the following parts, the
first number being added is the content of AX, and the second
number is the contents of BX. Give the resulting value of AX and tell
whether signed or unsigned overflow occurred.
a) 2143h-1986h
b) 81FEh-1986h
c) 19BCh-81FEh
d) 0002h-FE0Fh
e) 8BCDh-71ABh
2143h-1986h
2143= 0010 0001 0100 0011
1986= 0001 1001 1000 1101
0010 0001 0100 0011
- 0001 1001 1000 1101
0000 0111 1011 1101
AX=7BDh
Flow Set/clear reason
Signed 0 No borrow in , no borrow
out
unsigned 0 CF=0
81FEh-1986h
1000 0001 1111 1110
0001 1001 1000 0110
0110 1000 0111 1000
AX=6878h
Flow Set/clear reason
Signed 1 Borrow out but no borrow
in
unsigned 0 CF=0
19BCh-81FEh
0001 1001 1011 1100
1000 0001 1111 1110
1001 0111 1011 1110
AX=97BEh
Flow Set/clear reason
Signed 1 Borrow in but no borrow
out
7. unsigned 1 CF=1
0002h-FE0Fh
0000 0000 0000 0010
1111 1110 0000 1111
0000 0001 1111 0011
AX=01F3h
Flow Set/clear reason
Signed 0 Borrow in and borrow out
unsigned 1 CF=1
8BCDh-71ABh
1000 1011 1100 1101
0111 0001 1010 1011
0001 1010 0010 0010
AX=1A22h
Flow Set/clear reason
Signed 1 Borrow out but no borrow
in
unsigned 0 CF=0