Shift and Rotate Instructions
14.1 Shift Instructions
You can use the Shift instructions to move the contents of the low word of accumulator 1 or the contents of the whole accumulator bit by bit to the left or the right. Shifting by n bits to the left multiplies the contents of the accumulator by “2n”; shifting by n bits to the right divides the contents of the accumulator by “2n”. For example, if you shift the binary equivalent of the decimal value 3 to the left by 3 bits, you end up with 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 end up with the binary equivalent of the decimal value 4 in the accumulator.
The number that follows the shift instruction or a value in the low byte of the low word of accumulator 2 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 bit that is shifted last is loaded into the CC 1 bit of the status word (see Figure 2-7). 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 shift operations are unconditional, that is, their execution does not depend on any special conditions. They do not affect the result of logic operation.
The following instruction shift the contents of the low word of accumulator 1 bit by bit to the left or right:
Shift Left Word (SLW, 16 bits)
Shift Right Word (SRW, 16 bits)
The following instructions shift the entire contents of accumulator 1 bit by bit to the left or right:
Shift Left Double Word (SLD, 32 bits)
Shift Right Double Word (SRD, 32 bits) In all cases, the free bit positions are filled with a 0,
The following sample program and Figure 14-1 provide an example of how the SLW instruction works. Table 14-1 provides a summary of all the Shift instructions.
STL Explanation
L MW10 SLW 6 T MW20
Load the contents of memory word MW10 into the low word of accumulator 1.
Shift the bits of the low word in accumulator 1 six places to the left.
Transfer the contents of the low word of accumulator 1 to memory word MW20.
Shift and Rotate Instructions
15... ...8 7... ...0
0 1 0 1
0 1 0 1 0 1 0 1 0 0 0 0
0 1 0 0
1 1 0 1 0 0 0 0
1 1 1 1
0 0 0 0 1 1
6 places
These five bits are lost.
The bit that is shifted out last is stored in the CC 1 bit of the status word.
The vacated places are filled with zeros.
Figure 14-1 Shifting Bits of the Low Word of Accumulator 1 Six Bits to the Left
The following sample program and Figure 14-2 provide an example of how the SRW instruction works. Table 14-1 provides a summary of all the Shift instructions.
STL Explanation
L +3 L MD10
SRD T MD20
Load the value +3 into accumulator 1.
Load the contents of memory double word MD10 into
accumulator 1. The old contents of accumulator 1 (+3) is moved to accumulator 2.
Shift the bits in accumulator 1 three places to the right.
Transfer the contents of accumulator 1 to memory double word MD20.
1 1 1
31... ...16 15... ...0
1 1 1 1 1 1 1 1 0 1 0 1 0 1 0 1 1 0 1 0 1 0 1 0 1 1 1 1 1 1 1 1
0 1 0 1
0 0 0 1 1 1 1 1 1 1 1 0 1 0 1 0 1 0 1 1 0 1 0 1 1 1 1 1 3 places
The vacated places Shift Right Double
Word (32 Bits):
SRD
Shift and Rotate Instructions
The Shift Sign Integer (SSI, 16 bits) instruction shifts the contents of the low word of accumulator 1 bit by bit to the right, including sign, as described in the overview of this chapter:
The Shift Sign Double Integer (SSD, 32 bits) instruction shifts the entire contents of accumulator 1 bit by bit to the right, including sign.
The shift bit is copied into the free bit positions.
The following sample program and Figure 14-3 provide an example of how the SSI instruction works. Table 14-1 provides a summary of all the Shift instructions.
STL Explanation
L MW10 SSI 4 T MW20
Load the contents of memory word MW10 into the low word of accumulator 1.
Shift the bits in the low word of accumulator 1, including sign, four places to the right.
Transfer the contents of the low word of accumulator 1 to memory word MW20.
15... ...8 7... ...0
1 0 1 0
0 0 0 0 1 0 1 0 1 0 1 0
1 1 1 1
1 1 1 1 0 0 0 0
1 1 1 1 4 places
The bit that is shifted out last is stored in the CC 1 bit of the status word.
The vacated places are filled with the signal state of the sign bit.
1 0 1 0
These three bits are lost.
Sign bit
Figure 14-3 Shifting Bits of the Low Word of Accumulator 1 Four Bits to the Right with Sign Shift Functions:
Signed Numbers
Shift Sign Integer:
SSI
Shift and Rotate Instructions
Table 14-1 Overview of Shift Instructions
Instruction Area Affected Direction Indication of Number of Places to Shift
Left In the instruction statement
0 n=0 to 15
SLW Low word of
accumulator 1
Left In the low byte of the low word of accumulator 2
0 0 to 2552
SLD n Accumulator 1 Left In the instruction statement
0 n=0 to 32
SLD Accumulator 1 Left In the low byte of the low word of accumulator 2
0 0 to 2553
SRW n Low word of
accumulator 1
Right In the instruction statement
0 n=0 to 15
SRW Low word of
accumulator 1
Right In the low byte of the low word of accumulator 2
0 0 to 2552
SRD n Accumulator 1 Right In the instruction statement
0 n=0 to 32
SRD Accumulator 1 Right In the low byte of the low word of accumulator 2
0 0 to 2553
SSI n Low word of
accumulator 1
Right In the instruction statement
Sign bit n=0 to 15
SSI Low word of
accumulator 1
Right In the low byte of the low word of accumulator 2
Sign bit 0 to 2554 SSD n Accumulator 1 Right In the instruction
statement
Sign bit n=0 to 32
SSD Accumulator 1 Right In the low byte of the low word of accumulator 2
Sign bit 0 to 2555
1 If the number of bits by which to shift or rotate is 0, the instruction is executed like a NOP.
2 For shift numbers greater than 16, the result of the shift function is W#16#0000 and CC 1 = 0.
3 For shift numbers greater than 32, the result of the shift function is DW#16#0000_0000 and CC 1 = 0.
4 For shift numbers greater than 15, the result of the shift function is W#16#0000 and CC 1 = 0 or W#16#FFFF and CC 1 = 1 depending on the sign (0 or 1).
5 For shift numbers greater than 31, the result of the shift function is DW#16#0000_0000 (CC 1 = 0) or DW#16#FFFF_FFFF (CC 1 = 1) depending on the sign of the number of bits to be shifted.
Shift and Rotate Instructions