6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sat Apr 27, 2024 9:38 pm

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: ADC Instruction and BCD
PostPosted: Wed May 26, 2004 8:54 pm 
Offline

Joined: Fri May 21, 2004 5:23 pm
Posts: 17
Location: Burlington, ON
Hi,

I read that in when in decimal mode the Zero Flag is invalid. What does this mean? In other words, does it mean that the Zero Flag is not updated?

Thanks,

Andrew


Top
 Profile  
Reply with quote  
PostPosted: Thu May 27, 2004 1:12 am 
Offline
User avatar

Joined: Thu Mar 11, 2004 7:42 am
Posts: 362
andrewem wrote:
I read that in when in decimal mode the Zero Flag is invalid. What does this mean? In other words, does it mean that the Zero Flag is not updated?


No, the Z flag will always be affected by a ADC or SBC instruction. Invalid means that the Z flag does not always correctly reflect the result in the accumulator. For example, after:

Code:
SED
CLC
LDA #$99
ADC #$01


the accumulator is $00, but the Z flag is clear.

On the other hand, after:

Code:
SED
SEC
LDA #$01
SBC #$01


the accumulator is $00, but the Z flag is set. So the Z flag is sometimes correct, sometimes not.

The Z flag is only invalid on the 6502. On the 65C02 and the 65816, the Z flag correctly reflect the accumulator contents.

On the 6502, if you want to predict the value of the Z flag after an ADC or SBC, just add or subtract the numbers (accounting for the carry) as though they were binary number rather than BCD numbers. In other words, after:

Code:
SED
ADC NUMBER


the Z flag will be the same as after:

Code:
CLD
ADC NUMBER


assuming, of course, that upon entry, the accumulator and carry were the same. The same is true of SBC.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu May 27, 2004 11:01 am 
Offline

Joined: Fri May 21, 2004 5:23 pm
Posts: 17
Location: Burlington, ON
Thanks for the clear response :D.

Andrew


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 27 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: