Keil 8051 Tools
  C construct for Carry Flag?

Post New Topic  Post A Reply
profile | register | preferences | faq | search

UBBFriend: Email This Page to Someone! next newest topic | next oldest topic
Author Topic:   C construct for Carry Flag?
chuckcar
Member
posted August 25, 2010 12:34 PM     Click Here to See the Profile for chuckcar   Click Here to Email chuckcar     Edit/Delete Message
Hello,

I'd like to see if an addition set the carry flag?

Does Keil support such a processor dependent thing?

IP: Logged

chuckcar
Member
posted August 25, 2010 12:44 PM     Click Here to See the Profile for chuckcar   Click Here to Email chuckcar     Edit/Delete Message
OK, I see that there is a CY flag.

Yes I understand all the implications and tradeoffs.

Preach away if you must.

IP: Logged

worknhard9062
Member
posted August 25, 2010 01:01 PM     Click Here to See the Profile for worknhard9062   Click Here to Email worknhard9062     Edit/Delete Message
I take you at your word when you say you understand the implications and tradeoffs, so no preaching

All of the processor flags are defined in Keil header files and therefore available to individually test. My only concern would be that the compiled code between the action and the flag test might do something to affect the flag. I would carefully examine the assembly language output from the compiler to verify your code will do as you intend.

Happy programming.

------------------
Regards,
Steve C.

IP: Logged

hero_hont
New Member
posted September 10, 2010 12:18 AM     Click Here to See the Profile for hero_hont   Click Here to Email hero_hont     Edit/Delete Message
ok you.
do math calculation. I decide to limit the integer to 8 bits. If
it exceeds 0xFF, then Carry flag should be set. C++ Compiler does not
have the feature. I believe that it can be done to use if keyword.

For example

unsigned char Low_Byte = 0xFF;
unsigned char High_Byte = 0x20;
unsigned char Carry = 0x00;

Low_Byte++;

// Use IF to detect Carry
// How?
if (Carry ??? Low_Byte)
{
High_Byte++;
}


Please do not tell me to use short or long instead of char like this
below.

unsigned short Low_Byte = 0xFF;
unsigned short High_Byte = 0x20;
unsigned short Carry = 0;

Low_Byte++;
Carry = Low_Byte >> 8;
Low_Byte &= 0xFF;
High_Byte += Carry;

Thanks...

------------------
Vietnam Travel, Vietnam tours-Vietnam beaches- Hanoi tour and excursion

IP: Logged

vanmierlo
Member
posted September 10, 2010 02:35 AM     Click Here to See the Profile for vanmierlo   Click Here to Email vanmierlo     Edit/Delete Message
I decide to limit the integer to 8 bits.

Why would you do that if you need 16 bit integers anyway?

Low_Byte++;

// Use IF to detect Carry
// How?
if (Carry ??? Low_Byte)
{
High_Byte++;
}

Easy, check if Low_Byte == 0.

IP: Logged

All times are CT (US)

next newest topic | next oldest topic

Administrative Options: Close Topic | Archive/Move | Delete Topic
Post New Topic  Post A Reply
Hop to:

Contact Us | MCU User Forum

Have you seen our MCU Knowledge Base?


Ultimate Bulletin Board 5.47b