Understanding overflow flag for ADC on the 6502

Discuss emulation of the Nintendo Entertainment System and Famicom.

Moderator: Moderators

User avatar
Disch
Posts: 1848
Joined: Wed Nov 10, 2004 6:47 pm

Post by Disch »

ehguacho wrote:i guess the clearest way to set or reset the V flag in ADC and SBC instructiones is by testing if the result is major than 0x7f. it works in both instructions.
That actually does not work for either instruction.

Consider the following:

Code: Select all

LDA #$D0
CLC
ADC #2  ; this should CLEAR V
   ; your code would set V (wrong)
Your SBC code fails for the same reason
User avatar
ehguacho
Posts: 83
Joined: Tue Mar 09, 2010 11:12 pm
Location: Rosario, Argentina
Contact:

Post by ehguacho »

Disch wrote:
ehguacho wrote:i guess the clearest way to set or reset the V flag in ADC and SBC instructiones is by testing if the result is major than 0x7f. it works in both instructions.
That actually does not work for either instruction.

Consider the following:

Code: Select all

LDA #$D0
CLC
ADC #2  ; this should CLEAR V
   ; your code would set V (wrong)
Your SBC code fails for the same reason
why should it be failing? $D2 + 2 = $D2 > 127
maybe i'm wrong, but why?
sorry about my english, i'm from argentina...

http://nestate.uuuq.com
User avatar
tokumaru
Posts: 12106
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Post by tokumaru »

ehguacho wrote:why should it be failing? $D2 + 2 = $D2 > 127
maybe i'm wrong, but why?
$D0, as a signed number, is -48. Add 2 and it becomes -46 ($D2). There is no overflow.
Post Reply