Solved

explanation required

Posted on 2011-03-03
5
385 Views
Last Modified: 2012-06-27
I went through the following question / answer :

Assume that AX = BBBBh  and BX = BBBBh. What will be the contents
   of the AX register after the instruction:

      ADD AL,BL

   is executed.

   A. BBBBh    B. BBF6h   C. BB76h    D. BB78h    E. None of these

   Answer: C

   What will the condition code bits be after the instruction is
   executed.

   A. SF=0 ZF=0 OF=0 CF=1      B. SF=0 ZF=0 OF=1 CF=1

   C. SF=0 ZF=1 OF=0 CF=1      D. SF=1 ZF=0 OF=1 CF=1    E. None of the above

   Answer: B


I didn't understand why the OF is set to 1 can someone explain to me that ?

Thanks.
0
Comment
Question by:bachra04
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 53

Expert Comment

by:Infinity08
ID: 35031669
>> I didn't understand why the OF is set to 1 can someone explain to me that ?

OF is the overflow flag, and it is set if the previous instruction caused an (arithmetic) overflow.

In this case, ADD AL,BL caused an overflow, so the flag is set.
0
 
LVL 2

Author Comment

by:bachra04
ID: 35031964
I understand that :

BBh + BBh caused a carry that's why CF is set ;

But what confuses me is when do we say that there is Overflow; do you mean every time we have a carry we'll have overflow ?
Is there a case when we have overflow and not a carry ? or vice versa ?

Thanks
0
 
LVL 53

Accepted Solution

by:
Infinity08 earned 500 total points
ID: 35032253
There is an important distinction between the carry flag (CF) and the overflow flag (OF) :

CF : set if the LSB (least significant bit) of the neighboring more significant value would have been set by the instruction (useful for unsigned accition eg.)
OF : set if the MSB (most significant bit) changes due to the instruction (useful for signed addition eg.)

For example (in binary) :

        11111111 + 11111111 = 111111110

so, there is carry (because an extra 9th bit is set), but there is no overflow (because the 8th bit hasn't changed - it was 1 before and after).

And also :

        01111111 + 01111111 = 11111110

so there is no carry (the result still fits in the 8 bits), but there is overflow (because the 8th bit has changed from 0 to 1).
0
 
LVL 2

Author Comment

by:bachra04
ID: 35034040
Can the carry flag be set 1 in a substraction operation :

e.g : sub 11h, 44h
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 35034149
>> Can the carry flag be set 1 in a substraction operation :

In the case of a subtraction, the CF is set in case of what is called a borrow :

        00000001 - 00000010 = 11111111

In order for this (unsigned) subtraction to work, we need a borrow, to add a 9th 1 bit to the first operand :

        100000001 - 00000010 = 11111111

so the CF flag is set.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Building a cohesive image for your brand is vital to making an impression on consumers. When the economy is tough, brands do better than unbranded  products. This can have a huge impact on your long-term profits, as the economy goes up and down.
Active Directory security has been a hot topic of late, and for good reason. With 90% of the world’s organization using this system to manage access to all parts of their IT infrastructure, knowing how to protect against threats and keep vulnerabil…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question