Move (output instruction)
BTD: Bit Field Distribute
Copies a run of bits from one place in a register to another.
Also called: bit distribute, bit field move, unpack bits.
BTD(number, a, sbit, dbit, len)Arguments
| Name | What it is | Accepts | Default |
|---|---|---|---|
| destination | What the instruction acts on | a register | required |
| a | Source | a number or a tag | 0 |
| sbit | Source bit | a whole number | 0 |
| dbit | Dest bit | a whole number | 0 |
| len | Length | a whole number | 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
BTD takes a length of bits, starting at a bit position in the source, and drops them into the destination starting at a bit position of its own. Everything else in the destination is left alone.
The everyday use is unpacking. Networked devices pack several unrelated things into one word: a couple of status bits, a three bit mode field, a four bit fault code. Reading the mode field means pulling out bits 4 to 6 and shifting them down so that they read as a number you can compare against.
The same instruction packs as well as unpacks, which is how a small number is written into the middle of a command word without disturbing the bits on either side of it.
Bit positions start at 0, and bit 0 is the least significant, worth 1. Bit 4 is worth 16.
A rung you can run
Pull a three bit mode field out of a status word
ONS(Sim_Load)MOV(Drive_Status,208)
XIC(Comms_Ok)BTD(Drive_Mode,Drive_Status,4,0,3)
EQU(Drive_Mode,5)OTE(Mode_Is_Torque)208 is 11010000 in binary. Turn on Comms_Ok and BTD takes three bits starting at bit 4, which are 1, 0 and 1, and puts them at the bottom of Drive_Mode: the answer is 5. Now it is an ordinary number and an ordinary EQU can test it. Change the 4 to a 5 and watch the answer shift to the wrong field.
Run this rung in the simulatorWhat it is called on other controllers
| Platform | Equivalent |
|---|---|
| Rockwell (Studio 5000) | BTD |
| Siemens (TIA Portal) | No single instruction: shift and mask |
| Mitsubishi (GX Works) | No single instruction: shift and mask |
| CODESYS and IEC 61131-3 | No single instruction: SHR then AND |
Common mistakes
- Counting bits from 1. Every off-by-one here reads a field one place out, and the value that comes back is wrong but plausible, so it can survive testing.
- Assuming the rest of the destination is cleared. It is not, exactly as with MVM. If the destination held something before, the bits outside the field you wrote are still there and will still be read.
Practise it
Interactive exercises that use BTD. Each one checks your ladder against a real scan.
