Shift Functions

There are three sorts of Shift instruction :

(a) Logical Shift.

One bit 'falls off' (possibly into the Carry flag), and a 0 is shifted in.

Examples:

Logical shift RIGHT 01101011  
to get 00110101 .........[1] (Carry flag)
     
Logical shift RIGHT 10110001  
to get 01011000 .........[1] (Carry flag)

 

(b) Arithmetic shift.

Similar to a Logical shift, but the sign bit remains unchanged.

Examples:

Arithmetic shift RIGHT 01101011  
to get 00110101 .........[1] (Carry flag)
     
Arithmetic shift RIGHT 10110000  
to get 11011000 ..........[0] (Carry flag)

 

(c) Cyclic shift. (or Rotation)

In a cyclic right shift the content of the Carry flag is moved into the vacated bit.

Think of it as the bit 'falling off' going through the Carry Flag and round to the front of the number.

Examples:

Cyclic shift RIGHT 01101001  
to get 10110100 .........[1] (Carry Flag)
     
and again to get 01011010 .........[0] (Carry Flag)
     

Generally :

A (arithmetic) shift to the right is equivalent to dividing by 2.

A (arithmetic) shift to the left is equivalent to multiplying by 2.