Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
You are not logged in - nap
CSDb User Forums


Forums > C64 Coding > How is carry affected by compare?
2010-11-10 19:40
Mace

Registered: May 2002
Posts: 1799
How is carry affected by compare?

Somewhere I read that the carry is affected by the result of a compare.
It's not in the Prog.Ref.Guide, other than a flag in the register table.

How does this work?
2010-11-10 19:44
chatGPZ

Registered: Dec 2001
Posts: 11149
cmp works exactly like sbc, except the result isnt stored in A
2010-11-10 19:46
Oswald

Registered: Apr 2002
Posts: 5031
http://www.6502.org/tutorials/compare_beyond.html#2.1
2010-11-10 20:01
JackAsser

Registered: Jun 2002
Posts: 1995
@Groepaz: Is a CMP really affected by the decimal-bit, like SBC is?
2010-11-10 20:01
Mr. SID

Registered: Jan 2003
Posts: 424
cmp is like sbc but the carry is set before automatically, so you don't have to do that.
2010-11-10 20:18
Mace

Registered: May 2002
Posts: 1799
So in the following code, both SEC and CLC are useless?
	lda #{some value}
	sec
	cmp #$00
	beq !fwrd+
	clc
!fwrd:
	rts


I know that the whole CMP is not needed, but the purpose of the routine is to SEC when A<>0 and CLC when A=0.
2010-11-10 20:36
Oswald

Registered: Apr 2002
Posts: 5031
according to my link this should work:

cmp #$00
beq +
clc
+


(If the C flag is 1, then A (unsigned) >= NUM (unsigned) and BCS will branch)
2010-11-10 20:47
chatGPZ

Registered: Dec 2001
Posts: 11149
Quote:
@Groepaz: Is a CMP really affected by the decimal-bit, like SBC is?

i dont know - but internally a CMP really _is_ a SBC, ie the exact same operation is performed, using the same logic blocks. so it should be like you say, would make sense at least :)
2010-11-10 20:59
JackAsser

Registered: Jun 2002
Posts: 1995
Quote: according to my link this should work:

cmp #$00
beq +
clc
+


(If the C flag is 1, then A (unsigned) >= NUM (unsigned) and BCS will branch)


cmp #$01

>=1 => C=1
<1 => C=0
2010-11-10 21:07
Mace

Registered: May 2002
Posts: 1799
\o/
I love hardcore coding like this :-D
2010-11-10 22:11
Oswald

Registered: Apr 2002
Posts: 5031
Quote: cmp #$01

>=1 => C=1
<1 => C=0


you win. I had the idea that one cmp may be enough, but too tired to think it trough :P :)
 
... 27 posts hidden. Click here to view all posts....
 
Previous - 1 | 2 | 3 | 4 - Next
RefreshSubscribe to this thread:

You need to be logged in to post in the forum.

Search the forum:
Search   for   in  
All times are CET.
Search CSDb
Advanced
Users Online
jeroen1328
pcollins/Quantum
Mibri/ATL^MSL^PRX
Ben Breton/Absence o..
Knut Clausen/SHAPE/F..
Matt
Alakran_64
Sabbi/Hokuto Force
iAN CooG/HVSC
Smasher/F4CG
DJ Gruby/TRiAD
REBEL 1
Guests online: 130
Top Demos
1 Next Level  (9.7)
2 13:37  (9.7)
3 Mojo  (9.7)
4 Coma Light 13  (9.7)
5 Edge of Disgrace  (9.6)
6 No Bounds  (9.6)
7 Comaland 100%  (9.6)
8 Aliens in Wonderland  (9.6)
9 Uncensored  (9.6)
10 Wonderland XIV  (9.6)
Top onefile Demos
1 Happy Birthday Dr.J  (9.7)
2 Layers  (9.6)
3 It's More Fun to Com..  (9.6)
4 Cubic Dream  (9.6)
5 Party Elk 2  (9.6)
6 Copper Booze  (9.6)
7 TRSAC, Gabber & Pebe..  (9.5)
8 Rainbow Connection  (9.5)
9 Dawnfall V1.1  (9.5)
10 Daah, Those Acid Pil..  (9.5)
Top Groups
1 Nostalgia  (9.4)
2 Oxyron  (9.3)
3 Booze Design  (9.3)
4 Censor Design  (9.3)
5 SHAPE  (9.3)
Top Webmasters
1 Slaygon  (9.7)
2 Perff  (9.6)
3 Morpheus  (9.5)
4 Sabbi  (9.5)
5 CreaMD  (9.1)

Home - Disclaimer
Copyright © No Name 2001-2024
Page generated in: 0.057 sec.