Block that performs arithmetic left shift operation in a value passed by Value, storing the result in Result.
Ladder Representation

Block Structure
Variable Type |
Name |
Data Type |
Description |
VAR_INPUT |
EN |
BOOL |
Block enabling |
Value |
SINT INT DINT |
Variable to undergo shift |
|
Shift |
BYTE USINT |
Shift index |
|
VAR_OUTPUT |
ENO |
BOOL |
End of operation |
Result |
SINT INT DINT |
Variable that stores the result of the operation |
Operation
When this block has a TRUE value in EN, it sends to the Result output the value of the Value variable after performing a number of arithmetic right shifts, according to the Shift value.
|
NOTE! All arithmetic shifts implemented maintain the sign of the variable. |
When EN has FALSE value, Result remains unchanged.
The ENO value forwards to the next Ladder block the EN value after the operation is completed.
Block Flowchart

Example in Ladder

The above example performs an arithmetic right shift by three positions in the VALUE variable whose initial value is 52 (0011 0100 in binary). The bits on the right are being discarded, and on the left new zeros are inserted. The final result (0000 0110 in binary) is stored in RESULT.

The above example performs an arithmetic right shift by two positions in the VALUE variable whose initial value is -79 (1011 0001 in binary). The bits on the right will be discarded and new ones on the left are inserted, since the arithmetic right shifts preserve the sign of the variable. The final result (1111 0110 in binary) is stored in RESULT.

The above example performs an arithmetic right shift by thirteen positions in the VALUE variable whose initial value is -128 (1000 0000 in binary). The bits on the right are being discarded, and on the left new ones are inserted. The final result (1111 1111 in binary) is stored in RESULT.
Example in ST
The example below displays the instructions for applying the example above in the ST language.
VAR VALUE : SINT := -79; SHIFT : BYTE := 2; RESULT : INT; END_VAR
RESULT := FB_ASHR( EN:=DI1, Value:=VALUE, Shift:=SHIFT, ENO=>DO1);
|
|---|