
16-2
Ladder Logic (LAD) for S7-300 and S7-400
C79000-G7076-C504-02
16.1 Shift Instructions
You can use the Shift instructions to move the contents of input IN bit by bit
to the left or the right. Shifting to the left multiplies the contents of input IN
by 2 to the power n (2
n
); shifting to the right divides the contents of input IN
by 2 to the power n (2
n
). For example, if you shift the binary equivalent of
the decimal value 3 to the left by 3 bits, you obtain the binary equivalent of
the decimal value 24 in the accumulator. If you shift the binary equivalent of
the decimal value 16 to the right by 2 bits, you obtain the binary equivalent
of the decimal value 4 in the accumulator.
The number that you supply for input parameter N indicates the number of
bits by which to shift. The bit places that are vacated by the Shift instruction
are either filled with zeros or with the signal state of the sign bit (a 0 stands
for positive and a 1 stands for negative). The signal state of the bit that is
shifted last is loaded into the CC 1 bit of the status word (see Section 6.3).
The CC 0 and OV bits of the status word are reset to 0. You can use jump
instructions to evaluate the CC 1 bit.
The following Shift instructions are available:
S Shift Left Word, Shift Left Double Word
S Shift Right Word, Shift Right Double Word
S Shift Right Integer, Shift Right Double Integer
A signal state of 1 at the Enable (EN) input activates the Shift Left Word
instruction. This instruction shifts bits 0 to 15 of input IN bit by bit to the
left. There is no carry to bit 16.
Input N specifies the number of bits by which to shift. If N is larger than 16,
the command writes a 0 into the low word of accumulator 1 and resets the
CC 0 and OV bits of the status word to 0. The bit positions at the right are
padded with zeros. The result of the shift operation can be scanned at
output OUT.
The operation triggered by this instruction always resets the CC 0 and OV
bits of the status word to 0. If the box is executed (EN = 1), ENO shows the
signal state of the bit shifted last (same as CC 1 and RLO in the status word).
The result is that other functions following this box that are connected by the
ENO (cascade arrangement) are not executed if the bit shifted last had a
signal state of 0.
Certain restrictions apply to the placement of the Shift Left Word box (see
Section 6.1).
Shift Instructions
Shift Left Word
Shift and Rotate Instructions
Comentarios a estos manuales