base:rotate_byte_and_act_on_1-bits
no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
— | base:rotate_byte_and_act_on_1-bits [2016-03-03 21:01] (current) – created ftc | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Rotate byte and perform an action on each bit set to 1 ====== | ||
+ | Invented by Hoogo. Written by Frantic. | ||
+ | |||
+ | Sometimes you've got a byte value and for each bit you want to perform some action if the bit is set to 1 and do nothing, or something else, if the bit is set to 0. Hoogo came up with [[http:// | ||
+ | |||
+ | < | ||
+ | asl pattern | ||
+ | bcc no_action | ||
+ | inc pattern | ||
+ | ;Perform action here | ||
+ | ... | ||
+ | no_action: | ||
+ | </ | ||
+ | |||
+ | This works fine because ASL always shifts in a 0 as the new lsb in the byte and the INC, which changes the lsb to 1, is only executed if a 1 was shifted out into the carry flag by the ASL instruction. | ||
+ | |||
+ | In some circumstances it might be a better optimization to use 0 as flag for "take action" |
base/rotate_byte_and_act_on_1-bits.txt · Last modified: 2016-03-03 21:01 by ftc