Block that performs a 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 left 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 left shift by four positions (0100 in binary) in the VALUE variable whose initial value is -12 (1111 0100 in binary). The bits on the left will be discarded and on the right new zeros are inserted, since the arithmetic left shifts preserve the sign of the variable. The final result (1100 0000 in binary) is stored in RESULT.

The above example performs an arithmetic left shift by four positions (0100 in binary) in the VALUE variable whose initial value is 12 (0000 1100 in binary). The bits on the left will be discarded and on the right new zeros are inserted, since the arithmetic left shifts preserve the sign of the variable. The final result (0100 0000 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 := -12; SHIFT : USINT := 4; RESULT : SINT; END_VAR
RESULT := FB_ASHL( EN:=DI1, Value:=VALUE, Shift:=SHIFT, ENO=>DO1);
|
|---|