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?
 
... 27 posts hidden. Click here to view all posts....
 
2010-11-11 10:31
Mace

Registered: May 2002
Posts: 1799
This is now on Codebase64.

The route is CPU (6502/6510) >> General Stuff >> Changing Registers.
2010-11-11 12:26
Oswald

Registered: Apr 2002
Posts: 5076
uhh, rather remove that.. and add a link to the 6502.org tutorials... checking when A is zero is generally done with the Z bit anyway. It will just confuse newcomers.
2010-11-11 14:06
Mace

Registered: May 2002
Posts: 1799
Better extend the tut on Codebase, because I found the 6502.org explanation rather confusing.

It's not wrong what I wrote on Codebase, so why remove it?
2010-11-11 14:30
JackAsser

Registered: Jun 2002
Posts: 2014
Quote: Better extend the tut on Codebase, because I found the 6502.org explanation rather confusing.

It's not wrong what I wrote on Codebase, so why remove it?


@Mace: Indeed confusing. Personally I use the more simple explanation they have on: http://www.6502.org/tutorials/compare_instructions.html

Check the table labeled "Use of Branch Instructions with Compare". That is really all you need, promise.
2010-11-11 16:07
yago

Registered: May 2002
Posts: 332
The Part about "CMP is exactly like SBC" is also wrong
2010-11-11 19:15
Mace

Registered: May 2002
Posts: 1799
@Yago: it's Wiki, anyone can change it ;-)

I removed the page.
2010-11-12 09:21
GT
Account closed

Registered: Sep 2008
Posts: 308
CMP is:

sec
sbc

I use this method alot in 16-bits checks:

lda freq_low
cmp freq_low2
lda freq_high
sbc freq_high2
bcs/bcc whatever

2010-11-12 09:42
Oswald

Registered: Apr 2002
Posts: 5076
the carry is set because of the result of the cmp, and not beforehand.
2010-11-12 09:56
GT
Account closed

Registered: Sep 2008
Posts: 308
Quote: the carry is set because of the result of the cmp, and not beforehand.

What does the CPU do?

1. C=1
2. subtracts
3. changes C depending on result

It does it quicker than a sec+sbc, of course. Saving 2 cycles.
2010-11-12 13:43
Oswald

Registered: Apr 2002
Posts: 5076
Quote: What does the CPU do?

1. C=1
2. subtracts
3. changes C depending on result

It does it quicker than a sec+sbc, of course. Saving 2 cycles.


cmp does not do that. IMHO.

http://www.6502.org/tutorials/compare_beyond.html#2.1

also check the illegals, it clearly shows there's a separate sbc instruction that works without the 'C' bit. fex. DCP is a sideeffect of CMP.
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
JEZ
Linus/MSL
saimo/RETREAM
sLASH
wbochar
Avalanche/Atlantis
Hypnosis/TSD
LightSide
Guests online: 119
Top Demos
1 Next Level  (9.7)
2 13:37  (9.7)
3 Coma Light 13  (9.7)
4 Edge of Disgrace  (9.6)
5 Mojo  (9.6)
6 Uncensored  (9.6)
7 Wonderland XIV  (9.6)
8 Comaland 100%  (9.6)
9 No Bounds  (9.6)
10 Unboxed  (9.6)
Top onefile Demos
1 Layers  (9.6)
2 Party Elk 2  (9.6)
3 Cubic Dream  (9.6)
4 Copper Booze  (9.6)
5 Rainbow Connection  (9.5)
6 It's More Fun to Com..  (9.5)
7 Morph  (9.5)
8 Dawnfall V1.1  (9.5)
9 Onscreen 5k  (9.5)
10 Daah, Those Acid Pil..  (9.5)
Top Groups
1 Booze Design  (9.3)
2 Oxyron  (9.3)
3 Nostalgia  (9.3)
4 Censor Design  (9.3)
5 Triad  (9.2)
Top Webmasters
1 Slaygon  (9.6)
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.044 sec.