We've just updated MediaWiki and its underlying software. If anything doesn't look or work quite right, please mention it to us. --RanAS

Decimal Mode: Difference between revisions

From SnesLab
Jump to: navigation, search
(bolded title)
(→‎References: Intel article)
 
(17 intermediate revisions by the same user not shown)
Line 1: Line 1:
'''Decimal mode''' is one of the [[SNES]] CPU's processor flags. Toggling it on/off will only affect the instructions '''[[ADC]]''' and '''[[SBC]]'''. To toggle decimal mode on/off, use '''[[SED]]''' (Set decimal mode) and '''[[CLD]]''' (clear decimal mode)
'''Decimal mode''' is one of the [[SNES]] CPU's processor flags. It is bit 3 of the [[status register]].  Toggling it on/off will only affect the instructions '''[[ADC]]''' and '''[[SBC]]'''. To toggle decimal mode on/off, use '''[[SED]]''' (Set decimal mode) and '''[[CLD]]''' (clear decimal mode).


On the [[65c816]], it is cleared on reset.<sup>[2]</sup>  [[BRK]] clears it as well.
On the [[65c816]], it is cleared on reset.<sup>[2]</sup>  [[BRK]] and [[COP]] clear it as well.  [[RTI]] and [[PLP]] can affect the decimal mode flag too, as can [[SEP]] and [[REP]].


The [[negative flag|negative]], [[overflow flag|overflow]], and [[zero flag|zero]] flags are invalid in decimal mode.<sup>[3]</sup>
The [[negative flag|negative]], [[overflow flag|overflow]], and [[zero flag|zero]] flags are invalid in decimal mode on the NMOS 6502.<sup>[3]</sup>  But, they are valid in decimal mode on the 65c816.<sup>[7]</sup>
 
There are no conditional branch instructions that examine the decimal flag (such as BDS or BDC).<sup>[4]</sup>


== Processes ==
== Processes ==
Line 32: Line 34:
* [[DAS]]
* [[DAS]]
* [[Half-carry Flag]]
* [[Half-carry Flag]]
* [[Binary Coded Decimal]]


=== References ===
=== References ===
# Labiak, William.  Appendix C, page 357 conversion table: https://archive.org/details/Programming_the_65816/page/n367
# [[Labiak]], William.  Appendix C, [https://archive.org/details/Programming_the_65816/page/n367 page 357]. conversion table
# [[Eyes & Lichty]] page 262, https://archive.org/details/0893037893ProgrammingThe65816/page/262
# [[Eyes & Lichty]], [https://archive.org/details/0893037893ProgrammingThe65816/page/262 page 262]
# https://archive.org/details/0893037893ProgrammingThe65816/page/44
# lbid, [https://archive.org/details/0893037893ProgrammingThe65816/page/44 page 44]
# [[Eyes & Lichty]], [https://archive.org/details/0893037893ProgrammingThe65816/page/148 page 148]
# Pickens, John.  NMOS 6502 Opcodes.  http://www.6502.org/tutorials/6502opcodes.html#DFLAG
# Pickens, John.  NMOS 6502 Opcodes.  http://www.6502.org/tutorials/6502opcodes.html#DFLAG
# Clark, Bruce. http://www.6502.org/tutorials/decimal_mode.html
# Table 7-1 Caveats of 65c816 datasheet
# http://www.righto.com/2023/01/understanding-x86s-decimal-adjust-after.html?m=1


[[Category:ASM]]
[[Category:ASM]]
[[Category:Flags]]
[[Category:Flags]]
[[Category:Inherited from 6502]]
[[Category:Mode Select Flags]]

Latest revision as of 01:50, 21 September 2024

Decimal mode is one of the SNES CPU's processor flags. It is bit 3 of the status register. Toggling it on/off will only affect the instructions ADC and SBC. To toggle decimal mode on/off, use SED (Set decimal mode) and CLD (clear decimal mode).

On the 65c816, it is cleared on reset.[2] BRK and COP clear it as well. RTI and PLP can affect the decimal mode flag too, as can SEP and REP.

The negative, overflow, and zero flags are invalid in decimal mode on the NMOS 6502.[3] But, they are valid in decimal mode on the 65c816.[7]

There are no conditional branch instructions that examine the decimal flag (such as BDS or BDC).[4]

Processes

Let's just assume A is 8-bit and holds the value #$00. When one is doing ADC #$0C for example, the following steps will take place.

  • Take the parameter after ADC
  • Convert it to Decimal
  • Add the conversion to A (execute ADC)
  • If A turns out to have a hexadecimal number after the addition, convert it it to a decimal number again.

In this case, #$0C gets converted to 12. Since $0C equals to 12, doing ADC #$12 would give you the same result.

Same story with SBC, except SBC subtracts of course.

Example usage of ADC:

 LDA #$09  ;A = $09
 CLC       ;Clear carry flag
 ADC #$02  ;A = $11

The decimal mode has been documented more thoroughly in Ersanio's ASM tutorial V2.1.

See Also

References

  1. Labiak, William. Appendix C, page 357. conversion table
  2. Eyes & Lichty, page 262
  3. lbid, page 44
  4. Eyes & Lichty, page 148
  5. Pickens, John. NMOS 6502 Opcodes. http://www.6502.org/tutorials/6502opcodes.html#DFLAG
  6. Clark, Bruce. http://www.6502.org/tutorials/decimal_mode.html
  7. Table 7-1 Caveats of 65c816 datasheet
  8. http://www.righto.com/2023/01/understanding-x86s-decimal-adjust-after.html?m=1