6502.org
http://forum.6502.org/

[55] SBC & BCD
http://forum.6502.org/viewtopic.php?f=7&t=312
Page 1 of 1

Author:  ThomasHarte [ Mon May 22, 2000 11:56 am ]
Post subject:  [55.1] SBC & BCD

I now have all of my 6502 emulator working but for one thing - BCD arithmetic. I can't help wondering exactly what the process is for BCD arithmetic. I've tried several things and none of them seem to work quite correctly.

This ties in to a question I have about SBC. I have read in several places that SBC uses exactly the same logic as ADC except that all the bits are inverted first. This explains neatly why carry should be set for no borrow, but confuses me further with BCD arithmetic. How could ADC possibly just be an inverted SBC when BCD arithmetic is concerned?

None of the documents seem to cover this at all, and even the sole remaining 6502 book in the library skips over the matter.

Thanks in advance
-Thomas

Author:  fachat [ Thu May 25, 2000 6:32 pm ]
Post subject:  [55.2] SBC & BCD

Maybe you want to check the code of an

existing emulator, like the VICE C64
emulator. The homepage holds the

"64doc" file, that documents the 6502
opcodes incl. test programs und "undocumented" opcodes too.

Find the link on my homepage
http://www.6502.org/users/andre

Andre

Author:  uli_E [ Sat Jun 10, 2000 2:58 am ]
Post subject:  [55.3] SBC & BCD

I'd recommend one thing, Thomas.

Consider what happens when you add $66 to a packed BCD value in the range 0..99 and then to that, add a second packed BCD value of that same range. As you'll see, the addition of the hex66 causes the subsequent value of the result, the carry, and the overflow to take legitimate values. Now consider that two's complement addition simply takes the subtractor, complements it and adds a one, then adds that to the subtrahend. If you follow the same procedure, doesn't that yield the correct result?

Think about it!

regards,

Dick

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/