| |
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?
|
|
| |
chatGPZ
Registered: Dec 2001 Posts: 11386 |
cmp works exactly like sbc, except the result isnt stored in A |
| |
Oswald
Registered: Apr 2002 Posts: 5094 |
http://www.6502.org/tutorials/compare_beyond.html#2.1 |
| |
JackAsser
Registered: Jun 2002 Posts: 2014 |
@Groepaz: Is a CMP really affected by the decimal-bit, like SBC is? |
| |
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.
|
| |
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. |
| |
Oswald
Registered: Apr 2002 Posts: 5094 |
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) |
| |
chatGPZ
Registered: Dec 2001 Posts: 11386 |
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 :) |
| |
JackAsser
Registered: Jun 2002 Posts: 2014 |
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
|
| |
Mace
Registered: May 2002 Posts: 1799 |
\o/
I love hardcore coding like this :-D |
| |
Oswald
Registered: Apr 2002 Posts: 5094 |
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 |