base:set_a_byte_to_non-zero
no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
— | base:set_a_byte_to_non-zero [2015-04-17 04:33] (current) – created - external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Set a byte to non-zero ====== | ||
+ | //by White Flame// | ||
+ | |||
+ | Consider a flag in memory that is initialized to zero, but should become non-zero based on some check. | ||
+ | |||
+ | In this page, the " | ||
+ | |||
+ | |||
+ | ==== Using Register Values ==== | ||
+ | |||
+ | If a register is known to contain a non-zero value (or is free to immediately set its value), then a basic STA/STX/STY will MNZ. This is the only way to perform this operation without affecting the N or Z processor flags. | ||
+ | <code autoit> | ||
+ | STA flag | ||
+ | </ | ||
+ | However, sometimes our register values are unknown and must be preserved. | ||
+ | |||
+ | |||
+ | ==== Rolling a Carry Bit ==== | ||
+ | |||
+ | ROL/ | ||
+ | <code autoit> | ||
+ | SEC | ||
+ | ROL flag | ||
+ | </ | ||
+ | However, sometimes the carry state is unknown and must be preserved. | ||
+ | |||
+ | |||
+ | ==== Using INC/DEC ==== | ||
+ | |||
+ | Using INC or DEC to pull a value away from zero allows a flag to be MNZ'd up to 255 times, while preserving all of A, X, Y, and the Carry flag. | ||
+ | |||
+ | <code autoit> | ||
+ | INC flag | ||
+ | </ | ||
+ | |||
+ | However, sometimes we do not know how often the MNZ operation will be done between resets. | ||
+ | |||
+ | This final means ALWAYS guarantees a flag byte becomes non-zero without affecting A, X, Y, or C, no matter how often it's run between resets: | ||
+ | <code autoit> | ||
+ | : INC flag | ||
+ | BEQ :- | ||
+ | </ | ||
+ | The branch will be taken incredibly rarely. |
base/set_a_byte_to_non-zero.txt · Last modified: 2015-04-17 04:33 by 127.0.0.1