MOVE — Copy a Value
MOVE
Source
source
Dest
dest
Copies a source value (literal or tag) into a destination tag. When the source and destination are different numeric types, MOVE is also how you convert between them.
Operands
| Name | Type |
|---|---|
source | DINT | REAL |
dest | DINT | REAL |
How It Works
When the rung is true, source is read and written to dest every scan. When the rung is false, MOVE does nothing and dest keeps its last value.
Example — Change a Timer Preset at Run Time
Set a timer's preset based on which mode the machine is in.
XIC(ModeFast)MOVE(2000,CycleTimer.PRE);XIC(ModeSlow)MOVE(8000,CycleTimer.PRE)
While ModeFast is selected, CycleTimer.PRE is held at 2000. While ModeSlow is selected, it is held at 8000.
Example — Copy a Reading
XIC(SampleNow)MOVE(TempSensor,LastSample)
Type Conversion
Studio has no separate _TO_ conversion instructions (no REAL_TO_DINT, no DINT_TO_REAL). Conversion happens automatically when MOVE's source and destination types differ.
Conversion behavior in rungs.dev follows the same conventions as Studio 5000 Logix Designer®.
DINT → REAL (lossless for most values)
A DINT value is copied into a REAL with a decimal point added. For everyday values this is exact:
Source (DINT) | Destination (REAL) |
|---|---|
7 | 7.0 |
-1000 | -1000.0 |
16777216 | 16777216.0 |
A REAL can represent integers exactly up to about 16.7 million. Above that, the conversion is rounded to the nearest representable value. For example, 16777217 becomes 16777216.0. You'll only hit this with large counters or accumulators — for everyday tags it's not something to worry about.
REAL → DINT (banker rounding)
The fractional part has to go somewhere, so Studio uses banker rounding — also called round half to even. Halves go to the nearest even integer; non-halves round normally.
Source (REAL) | Destination (DINT) |
|---|---|
0.5 | 0 |
1.5 | 2 |
2.5 | 2 |
3.5 | 4 |
-2.5 | -2 |
1.4 | 1 |
1.6 | 2 |
MOVE(2.5, DintTag) // DintTag = 2
MOVE(3.5, DintTag) // DintTag = 4
For more on why halves round to the nearest even number rather than always up, see the Arithmetic and Comparison Operators page.
REAL → DINT overflow
After rounding, a finite REAL that is outside the DINT range overflows into the stored 32-bit DINT bit pattern. For example, 2147483648.0 stores as -2147483648.
REAL → DINT with non-finite values
If the source is +Infinity, -Infinity, or NaN (which can happen after a divide-by-zero), Studio clamps the value to the DINT range so an integer tag never holds a non-numeric value.
Source (REAL) | Destination (DINT) |
|---|---|
+Infinity | 2147483647 (MAX) |
-Infinity | -2147483648 (MIN) |
NaN | 0 |
Masked Move (MVM)
MVM
Source
source
Mask
mask
Dest
dest
MOVE overwrites the whole destination. MVM is a masked move. Copies the Source bits that the Mask lets through into the destination, leaving the destination bits under a 0 mask bit unchanged. Where a mask bit is 1, that bit of dest takes the Source value; where a mask bit is 0, that bit of dest keeps what it had.
| Name | Type |
|---|---|
source | DINT |
mask | DINT |
dest | DINT |
MVM(StatusWord,16#00FF,Result)
With mask 16#00FF, only the low 8 bits of StatusWord are copied into Result; the top 24 bits of Result are left untouched. A mask of 16#FFFFFFFF copies everything (the same as MOVE); a mask of 0 copies nothing. Write the mask in hexadecimal or binary so the passed-through bits are obvious.
Unlike MOVE, MVM works on bit patterns, so its operands are DINT only — there is no REAL masked move.
Common Mistakes
- Moving a
REALinto aDINTdestination without expecting rounding — the fractional part is gone, and halves snap to the nearest even integer (so2.5 → 2, not3). - Treating
MOVEas a free transfer between any two types — it works for numbers (DINT↔REAL), but not for structured types likeTIMERorCOUNTER. - Expecting
MVMto clear the bits the mask blocks — it doesn't. Bits under a0mask bit keep their current destination value; useCLRor a plainMOVEfirst for a clean slate.
Related
- Logical & bit instructions —
AND/OR/XOR/NOTcombine words bit-by-bit,CLRclears one, andBTDmoves a run of bits - Compare instructions — inspect values rather than move them
- Math instructions — compute values, then
MOVEor assign directly - Arithmetic and Comparison Operators — full division, rounding, and coercion rules