For what it's worth, when using subwf, and the result is negative, the PIC mid range reference manual says that the carry flag should be zero, (with don't care on entry to the instruction) However, my experiments (with an F872) showed that this was not the case, and a clrc had to be issued beforehand, otherwise it could stay at a 1. Regards, Kevin ----- Original Message ----- From: "Bob Ammerman" To: Sent: Friday, May 18, 2001 1:09 AM Subject: Re: [EE]: carry result: Robin Abbott > > Bob, > > > > I was taught that you use it as a carry/borrow (read carry not borrow) bit > depending upon the previous operation. All of this is as you have said a > "natural consequence" of two's complement arithmetic, which allows a value > to be added (or subtracted) across multiple bytes (words, etc.) by adding > the carry (or subtracting the borrow) on each higher order byte ... > > > > David W. Gulley > > Destiny Designs > > David, that is an excellent way to look at it. > > Bob Ammerman > RAm Systems > (contract development of high performance, high function, low-level > software) > > > > > On Thu, 17 May 2001, Bob Ammerman wrote: > > > David: > > > > > > The PIC microcontrollers use the convention that after a subtract, the > carry > > > flag is set if there was _no_ borrow. The carry flag if clear if there > was a > > > borrow. > > > > > > This may seem backwards, but it turns that it is a natural consequence > of > > > implementing subtraction as the addition of the twos complement. > > > > > > Here is an example. Say you want to compute 10-4: > > > > > > In binary: > > > > > > 1010 - 0100 > > > > > > Converting to addition of the twos complement: > > > > > > 1010 + 1100 = Carry + 0110 > > > > > > Note that there was no borrow, but carry was set. > > > > > > Now on the other hand, say you want to compute 4-10: > > > > > > In binary: > > > > > > 0100 - 1010 > > > > > > Converting to addition of the twos complement: > > > > > > 0100 + 0110 = 1010 > > > > > > Note that there is a borrow, but carry was not set. > > > > > > Some processors contain special logic to reverse the meaning of carry > for a > > > subtract instruction, but the PICs do not. IMHO such logic is a waste of > > > silicon. Dealing with the inversion is a simple matter for the compiler > or > > > the assembly language programmer. > > > > > > Bob Ammerman > > > RAm Systems > > > (contract development of high performance, high function, low-level > > > software) > > > > > > > > > ----- Original Message ----- > > > From: "David Cary" > > > To: > > > Sent: Thursday, May 17, 2001 2:53 PM > > > Subject: [EE]: carry result: Robin Abbott > > > > > > > > > > Dear PICers, > > > > > > > > I've just taken over maintenance of page > > > > http://www.piclist.com/techref/microchip/compcon.htm > > > > . > > > > It claims that Robin Abbott once said > > > > > > > >
> > > > Mind you it would have been easier if Microchip had simply > > > > put the logic in Hardware to "correct" the carry flag after a > subtraction! > > > >
> > > > > > > > What is the "correct" Carry result after a subtraction ? > > > > I have some friends that are making tiny CPUs inside FPGAs, > > > > and I'm sure they want to pick whatever Carry flag result > > > > makes the software guys happy. Which would be ... ? > > > > > > > > -- > > > > David Cary > > > > > > > > MAILER-DAEMON@eagle.mail.pipex.net on 2001-05-17 01:32:40 PM tells me > that > > > > : > > > > This account does not exist > > > > > > > > -- > > > > http://www.piclist.com hint: PICList Posts must start with ONE topic: > > > > [PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads > > > > > > > > > > > > > > -- > > > http://www.piclist.com hint: PICList Posts must start with ONE topic: > > > [PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads > > > > -- > > http://www.piclist.com hint: PICList Posts must start with ONE topic: > > [PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads > > > > > > -- > http://www.piclist.com hint: PICList Posts must start with ONE topic: > [PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads > > > -- http://www.piclist.com hint: The list server can filter out subtopics (like ads or off topics) for you. See http://www.piclist.com/#topics