David Cary wrote: > 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 ... ? ... Which would be the result that makes sense for the NEXT byte in a multi-byte subtraction. The actual state of the carry after a subtraction doesn't matter; the important thing is that if you implement a subtract-with-carry instruction, the description of the carry-out has to match the description of the carry-in. For instance... The 6502 indicates a borrow with a CLEAR carry-out, and all subtractions use the carry-in to indicate whether there was a borrow from a previous subtraction... So before performing a one-byte subtraction on the 6502, you must explicitly SET the carry. If you're doing a multi-byte subtraction, your code is simply: Set Carry Subtract Low Byte Subtract Middle Byte Subtract High Byte On the PICs, the carry also happens to be cleared by a borrow, but (unless you're using a device with a subtract-with-borrow instruction) it makes absolutely no difference whatsoever; the code to do a multi-byte subtraction has to explicitly look at the carry bit, and a "SKPC/INCFSZ" takes just as much space and time as a "SKPNC/INCFSZ" Some processors (like the 8051) use the opposite convention (borrow = carry set), but that's no more or less efficient as the 6502 convention; on an 8051, the first line of the above example just changes to "Clear the carry". Personally, I prefer the "borrow = carry clear" convention (as in the 6502 and PIC), but that's just personal preference. -Andy === Andrew Warren --- aiw@cypress.com === Staff Systems Engineer, IPD === Cypress Semiconductor Corporation -- http://www.piclist.com hint: PICList Posts must start with ONE topic: [PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads