Move (output instruction)

MVM: Masked Move

Moves only the bits selected by a mask, leaving the rest of the destination untouched.

Also called: masked move, move through a mask.

MVM(number, a, b)

Arguments

NameWhat it isAcceptsDefault
destinationWhat the instruction acts ona registerrequired
aSourcea number or a tag0
bMaska number or a tag-1

Arguments are positional and this table is generated from the simulator's own instruction registry, so it always matches what the engine accepts.

What it does

MOV overwrites the whole destination. MVM overwrites only the bits the mask selects and leaves every other bit of the destination exactly as it was.

That matters whenever a register has more than one owner. A drive command word where your program owns the lowest four bits and the HMI owns the rest is the everyday case: a MOV would write your four bits and wipe theirs in the same instruction, and the fault shows up as the panel mysteriously losing settings whenever the machine starts.

The mask is read as bits, so a mask of 15 is the lowest four bits (1 plus 2 plus 4 plus 8) and a mask of 256 is bit 8 on its own. Everything the mask does not select comes through from the old value of the destination.

A rung you can run

Write your bits into a word somebody else also writes to

RUNG 1PPanel_Sets_BitMOV Drive_Command:= 256RUNG 2PRun_PBMVM Drive_Command3 mvm 15RUNG 3PStop_PBMVM Drive_Command0 mvm 15
ONS(Panel_Sets_Bit)MOV(Drive_Command,256)
ONS(Run_PB)MVM(Drive_Command,3,15)
ONS(Stop_PB)MVM(Drive_Command,0,15)

Press Panel_Sets_Bit first: that puts 256 in the word, standing in for a bit the HMI owns. Now press Run_PB and Stop_PB and watch the low four bits change between 3 and 0 while 256 stays where it is. Replace either MVM with a MOV and the panel's bit is gone the first time you press a button.

Run this rung in the simulator

What it is called on other controllers

PlatformEquivalent
Rockwell (Studio 5000)MVM
Siemens (TIA Portal)No single instruction: AND the destination with the inverse mask, then OR the new bits in
Mitsubishi (GX Works)No single instruction: WAND and WOR in sequence
CODESYS and IEC 61131-3No single instruction: (dest AND NOT mask) OR (source AND mask)

Common mistakes

  • Leaving the mask at all bits. MVM with a mask of -1 selects every bit and is then simply a slower MOV, which quietly removes the protection you added the instruction for.
  • Expecting the unselected bits to be cleared. They are not, and that is the whole point: they keep whatever the destination already held. If you want them zeroed, clear the register first.

Practise it

Interactive exercises that use MVM. Each one checks your ladder against a real scan.

Related instructions

All ladder logic instructions