Skip to main content
rottendog2
Associate
December 27, 2004
Question

Stupid Arithmetic Compare / Carry Flag question

  • December 27, 2004
  • 2 replies
  • 865 views
Posted on December 27, 2004 at 06:24

Stupid Arithmetic Compare / Carry Flag question

This topic has been closed for replies.

2 replies

rottendog2
Associate
December 26, 2004
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 III
December 27, 2004
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