1. right offset operation SHR/SHRD

1. right offset operation SHR/SHRD

1.1. Instruction Description

The instruction moves the input word (S) value to the right (N) bits and loads the result into the output word (D). The shift instruction adds 0 to each shifted bit. If the number of shifts (N) is greater than or equal to 16 (SHRD instruction is 32), the value can be shifted up to 16 times (SHRD 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(SHR)

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(SHRD)

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

SHR D0 K1 D1 // Shift D0 to the right by 1 bit and output to D1

NETWORK 001

LD X001

SHRD D2 K16 D4 // Shift (D2, D3) to the right by 16 bits and output it to (D4, D5). In reality, D4=0, D5=D2.

SHR

图1 SHR