← All exercises

Stateful Masked Move

medium

Copies selected source bits into a retained word while preserving its previous unselected bits.

What it teaches

A masked move is a read-modify-write: the destination is also an input. A 1 mask bit updates from Source; a 0 preserves the destination's previous bit. Example: Source 5 with Mask 5 first produces 5. Changing Source to 2 and Mask to 2 then produces 7 because bit 1 updates while bits 0 and 2 remain stored. Unlike Set Selected Bits, a selected source bit can clear as well as set.

Inputs and outputs

TagTypeDefaultDescription
In_SourceDINT5New values for the selected destination bits
Cfg_MaskDINT5A 1 updates from Source; a 0 preserves the destination
Out_WordDINTRetained destination word

Required behavior