1. Left offset operation SHL/SHLD
1. Left offset operation SHL/SHLD
1.1. Instruction Description
The instruction shifts the value of the input register (S) by N bits to the left and loads the result into the output register (D). The shift instruction adds 0 to each shifted bit. If the number of shifts (N) is greater than or equal to 16 (SHLD instruction is 32), the value can be shifted up to 16 times (SHLD instruction is 32). If the number of shifts is greater than 0, the value of the last shift will be copied to the shift instruction overflow flag (M8166). If the result of the shift operation is 0, set the zero flag (M8167) of the shift instruction to 0.
| Related registers | Description |
|---|---|
| M8166 | The last bit to be removed. |
| M8167 | The result of the shift operation is 0. |
1.2. The valid operands of the instruction
1.2.1. Single word Instruction(SHL)
| Input/Output | Data Type | operand | Description |
|---|---|---|---|
| IN1 | 16 bit unsigned integer | D/CV/TV/AI/AO/K/H/V/Z/FD, bit composite word (X/Y/M/C/T/S), local variable (LW) | Input |
| IN2 | 16 bit unsigned integer | D/CV/TV/AI/AO/K/H/V/Z/FD, bit composite word (X/Y/M/C/T/S), local variable (LW) | shift |
| OUT | 16 bit integer | D/CV/TV/AO/V/Z, bit composite word (Y/M/C/T/S), local variable (LW) | output |
1.2.2. Double word instruction(SHLD)
| Input/Output | Data Type | operand | Description |
|---|---|---|---|
| IN1 | 32-bit unsigned integer | D/CV/K/H/FD, bit composite word (X/Y/M/C/T/S), local variable (LD) | input |
| IN2 | 32-bit unsigned integer | D/CV/K/H/FD, bit composite word (X/Y/M/C/T/S), local variable (LD) | shift |
| OUT | 32-bit integer | D/CV, bit composite word (Y/M/C/T/S), local variable (LD) | output |
1.3. Example
command table
NETWORK 000
LD X000
SHL D0 K1 D1 // Shift D0 left by 1 bit and output to D1
NETWORK 001
NETWORK 001
LD X001
SHLD D2 K16 D4 // Shift (D2, D3) by 16 bits to the left and output it to (D4, D5). In reality, D4=D3, D5=0.
图1 SHL