Truncated match.
PICList
Thread
'Subtraction Carry'
1997\01\22@163242
by
Bob Fehrenbach
I'm sure Andy Warren will want to take a shot at this, but
just in case he is busy --
Byon Garrabrant <spam_OUTbyonTakeThisOuT
NETCOM12.NETCOM.COM> wrote:
>What does the carry flag represent after a PIC subtraction? I've
>heard from one place that it should be thought of as a "non-negative
>result" flag, but that doesn't always work. The PSIM simulator gave
>the following reslts for these values:
>
>-4 - -2 = -2 No Carry
>-4 - 2 = -6 Carry
>
Byon,
PICs don't do signed arithmetic. The basic instructions treat each
opperand as an 8 bit absolute value.
-4 - -2 : The PIC sees this as b'11111100' - b'11111110'
which clearly negative, hence, no carry.
-4 - 2 : b'11111100' - b'00000010'
which is clearly non-negative, hence a carry.
--
Bob Fehrenbach Wauwatosa, WI .....bfehrenbKILLspam
@spam@execpc.com
1997\01\22@192508
by
Walter Banks
>What does the carry flag represent after a PIC subtraction? I've
>heard from one place that it should be thought of as a "non-negative
>result" flag, but that doesn't always work.
I just pulled some code from my simulator. The subtract on
a PIC is the following sequence.
j = arg + ((~ W) + 1) ;
if ((j & 0x100) != 0)
set_carry();
else
clr_carry();
w = j & 0xff;
The important thing is the increment takes place before the
add on a PIC, this does not happen in many processors. The
case to look at is when you subtract W that contains a 0xff
from 0 . Subtracts can be lots of fun. Compare the subtracts
on 6805, COP8, Z8, and 6502.
Walter Banks
http://www.bytecraft.com
More... (looser matching)
- Last day of these posts
- In 1997
, 1998 only
- Today
- New search...