Wikipedia

Search results

Tuesday 13 August 2013

Shift and Rotate

 Shift instructions move a bit string (or operand treated as a bit string) to the right or left, with excess bits discarded (although one or more bits might be preserved in flags). In arithmetic shift left or logical shift left zeros are shifted into the low-order bit. In arithmetic shift right the sign bit (most significant bit) is shifted into the high-order bit. In logical shift right zeros are shifted into the high-order bit.

Rotate instructions are similar to shift instructions, ecept that rotate instructions are circular, with the bits shifted out one end returning on the other end. Rotates can be to the left or right. Rotates can also employ an extend bit for multi-precision rotates.

Shift Operations

·         The ALU used in the 6800 performs shift and rotate operations.  The ASL, ASR and LSR instructions are shown in Figure 3.15



Figure 3.15: 6800 Shift Instruction :  (a) Arithmetic Shift Left (ASL)
(b) Arithmetic Shift Right (ASR)   (c) Logical Shift Right (LSR)

·         In the ASL operation, the MSB is shifted out of the data word into the Carry bit.  The LSB is filled with a 0.
·         The ASR operations shifts each bit to the right and moves the LSB into the  Carry bit.  The MSB, however, is retained and is also shifted into bit 6.  If the bits in the register are considered as a 2’s complement number; this method of shifting preserves the sign of the number.  The ASR is equivalent to dividing the number in the register by 2, regardless of the sign of the number.
·         The LSR operation simply shifts each bit one position to the right.  The MSB becomes a 0 and the LSB goes into the Carry bit.



                        Rotations

·         Two additional shifting instructions are ROL (Rotate Left) and ROR (Rotate Right) shown in Figure 3.16.  These are special forms of circular shifting, where the bits coming off one end of the word are inserted into the Carry bit, whereas the contents of the Carry bit are transferred into the vacated bit position.
·         There are many uses for Rotate instructions.  One application is to determine parity of a byte.  If the bits of the byte are successively shifted into the Carry bit, the number of 1’s can be counted and the parity can be determined as an ODD or EVEN number. 



No comments:

Post a Comment