cancel
Showing results for 
Search instead for 
Did you mean: 

Stupid Arithmetic Compare / Carry Flag question

rottendog2
Associate II
Posted on December 27, 2004 at 06:24

Stupid Arithmetic Compare / Carry Flag question

2 REPLIES 2
rottendog2
Associate II
Posted on December 26, 2004 at 15:32

Have a simple question that I cannot find in the ST7 programming manual or any support documentation. Does anyone know the relationship of the carry flag to the Arithmetic Compare command?

CP A,#$09

The reason I ask, is because the 6500 code I am converting uses what seems to be the same command which would be

CMP #$09

The 6500 sets the carry flag if the memory (in this case the number 9) is less than or equal to the A register.

From what I can tell with simple programs, it looks like ST arithmetic compare sets the Carry Flag if the memory is greater than the A register.

Very confusing.

wolfgang2399
Associate II
Posted on December 27, 2004 at 06:24

The carry-flag is meant to be a borrow-flag in the CP instruction of ST7 controllers. It is set when dst < src at CP dst,src (--> dst-src).

You can see it analogous to the SUB, SBC commands. To subtract a double byte number you will use e.g.

...

sub A,LSByte

ld A,X

sbc A,MSByte

ld X,A

...

With the relationship of SBC dst,src :

dst <-- dst-src-C

it won't work but with the described relation.

Pay attention to the DEC and INC commands as the carry flag is unaffected there .

Regards WoRo