liveBook · Manning

Cld instruction

As explained in Classic Game Programming on the NES: Make your own retro video game

The CLD instruction clears the 6502 decimal-mode flag.

CLD clears the 6502 decimal-mode flag. On the NES, whose 6502 does not support decimal mode, this ensures normal arithmetic operations are used during startup. section 5.12

Disable decimal mode during reset

Place CLD before configuring the stack and continuing NES initialization: cld #1 ldx #$FF txs #2 The following instructions prepare the stack pointer after decimal mode has been disabled. section 5.12

How Classic Game Programming on the NES: Make your own retro video game covers it

How deep it goes
Defines BCD behavior and flag effects, then demonstrates one startup use without developing arithmetic examples.
Examples
Uses a reset fragment containing CLD, LDX, and TXS before further NES setup.
What you can do after
Apply it in 6502 assembly to select normal arithmetic during NES startup.
How it connects
Connects 6502 assembly with decimal mode, BCD, SED, and NES hardware initialization.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Classic Game Programming on the NES: Make your own retro video game. The section links point to the parts of the book it draws on.