Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com
Table of contents
1.
Introduction
2.
What are Shift Micro-Operations in Computer Architecture?
2.1.
Logical Shift
2.1.1.
Logical Shift Left
2.1.2.
Logical Shift Right
2.2.
Arithmetic Shift
2.2.1.
Arithmetic Shift Left
2.2.2.
Arithmetic Shift Right
2.3.
Circular Shift
2.3.1.
Circular Shift Left
2.3.2.
Circular Shift Right
3.
Frequently Asked Questions
3.1.
What are the Shift micro-operations?
3.2.
What are different shift micro-operations?
3.3.
What is logic micro-operation and shift micro-operation?
4.
Conclusion
Last Updated: Mar 27, 2024
Medium

Shift Micro-Operations in Computer Architecture

Author Pakhi Garg
1 upvote
Shift Micro-Operations in Computer Architecture

Introduction

As you know, a computer works on instructions. Our systems consist of machine instructions to perform some operations like add, subtract, multiply, divide etc. To perform these operations, the system stores the data in registers. Now, to operate this data, the CPU has micro-operations. A micro-operation is a simple operation performed on the data stored in one or more registers. They transfer the data between registers. There are four types of micro-operations:-

  • Register micro-operations
  • Arithmetic micro-operations
  • Logic micro-operations
  • Shift micro-operations

In this blog, we will discuss shift micro-operations.

Recommended Topic, Microinstruction in Computer Architecture

What are Shift Micro-Operations in Computer Architecture?

Shift micro-operations are used when the data is stored in registers. These micro-operations are used for the serial transmission of data. Here, the data bits are shifted from left to right. These micro-operations are also combined with arithmetic and logic micro-operations and data-processing operations.

There are three types of shift micro-operations-

  1. Logical Shift
  2. Arithmetic Shift
  3. Circular Shift

Let’s start with logical shift micro-operation.

Logical Shift

The logical shift micro-operation moves the 0 through the serial input. There are two ways to implement the logical shift.

  1. Logical Shift Left
  2. Logical Shift Right

Let’s discuss both of them one by one.

Logical Shift Left

Each bit in the register is shifted to the left one by one in this shift micro-operation. The most significant bit (MSB) is moved outside the register, and the place of the least significant bit (LSB) is filled with 0. 

For example, in the below data, there are 8 bits 00001010. When we perform a logical shift left on these bits, all these bits will be shifted towards the left. The MSB or the leftmost bit i.e. 0 will be moved outside, and at the rightmost place or LSB, 0 will be inserted as shown below.

Logical Shift Left

To implement the logical shift left micro-operation, we use the shl symbol.  

For example, R1 -> shl R1.

This command means the 8 bits present in the R1 register will be logically shifted left, and the result will be stored in register R1.

Moreover, the logical shift left microoperation denotes the multiplication of 2. The example we’ve taken above when converted into decimal forms the number 10. And the result after the logical shift operation when converted to decimal forms the number 20. 

Next, we will see the logical shift right micro-operation.

Logical Shift Right

Each bit in the register is shifted to the right one by one in this shift micro-operation. The least significant bit (LSB) is moved outside the register, and the place of the most significant bit (MSB) is filled with 0. 

For example, in the below data, there are 8 bits 00000101. When we perform a logical shift right on these bits, all these bits will be shifted towards the right. The LSB or the rightmost bit i.e. 1 will be moved outside, and at the leftmost place or MSB, 0 will be inserted as shown below.

Logical Shift Right

To implement the logical shift right micro-operation, we use the shr symbol.  

For example, R1 -> shr R1.

This command means the 8 bits present in the R1 register will be logically shifted right, and the result will be stored in register R1.

Logical right shift micro-operation generally denotes division by 2. The inputted bits when converted into decimal form the number 5. And the outcome when converted into decimal forms the number 2. 

Next, we will study arithmetic shift micro-operation.

Arithmetic Shift

The arithmetic shift micro-operation moves the signed binary number either to the left or to the right position. There are two ways to implement the arithmetic shift.

  1. Arithmetic Shift Left
  2. Arithmetic Shift Right

Let’s discuss both of them one by one.

Arithmetic Shift Left

The arithmetic shift left micro-operation is the same as the logical shift left micro-operation. Each bit in the register is shifted to the left one by one in this shift micro-operation. The most significant bit (MSB) is moved outside the register, and the place of the least significant bit (LSB) is filled with 0. 

For example, in the below data, there are 8 bits 00100011. When we perform the arithmetic shift left on these bits, all these bits will be shifted towards the left. The MSB or the leftmost bit i.e. 0 will be moved outside, and at the rightmost place or LSB, 0 will be inserted as shown below.

Arithmetic Shift Left

The given binary number (00100011) represents 35 in the decimal system. And the binary number after logical shift left (01000110) represents 70 in a decimal system. Since 35 * 2 = 70. Therefore, we can say that the arithmetic shift left multiplies the number by 2.

To implement the arithmetic shift left micro-operation, we use the ashl symbol.  

For example, R1 -> ashl R1.

This command means the 8 bits present in the R1 register will be arithmetic shifted left, and the result will be stored in register R1.

Arithmetic Shift Right

Each bit in the register is shifted to the right one by one in this shift micro-operation. The least significant bit (LSB) is moved outside the register, and the place of the most significant bit (MSB) is filled with the previous value of MSB. 

For example, in the below data, there are 8 bits 10100011. When we perform an arithmetic shift right on these bits, all these bits will be shifted towards the right. The LSB or the rightmost bit i.e. 1 will be moved outside, and at the leftmost place or MSB, the previous MSB value, i.e. 1, will be inserted as shown below.

Arithmetic Shift Right

Arithmetic right shift divides the number by 2.

To implement the arithmetic shift right micro-operation, we use the ashr symbol.  

For example, R1 -> ashr R1.

This command means the 8 bits present in the R1 register will be arithmetic shifted right, and the result will be stored in register R1.

Next, we will study circular shift micro-operation.

Circular Shift

The circular shift, also known as the rotate shift, moves the bits in the register's sequence around both ends, thus ensuring no loss of information. There are two ways to implement the circular shift.

  1. Circular Shift Left
  2. Circular Shift Right

Let’s discuss both of them one by one.

Circular Shift Left

Each bit in the register is shifted to the left one by one in this shift micro-operation. After shifting, the least significant bit (LSB) place becomes empty, so it is filled with the value at the most significant bit (MSB). 

For example, in the below data, there are 8 bits 00010100. When we perform a circular shift left on these bits, all these bits will be shifted towards the left. The MSB or the leftmost bit i.e. 0 will be placed at the rightmost place or LSB as shown below.

Circular Shift Left

To implement the circular shift left micro-operation, we use the cil symbol.  

For example, R1 -> cil R1.

This command means the 8 bits present in the R1 register will be circular shifted left, and the result will be stored in register R1.

Next, we will discuss circular shift right micro-operation.

Circular Shift Right

Each bit in the register is shifted to the right one by one in this shift micro-operation. After shifting, the most significant bit (MSB) place becomes empty, so it is filled with the value at the least significant bit (LSB). 

For example, in the below data, there are 8 bits 00010100. When we perform a circular shift right on these bits, all these bits will be shifted towards the right. The LSB or the leftmost bit, i.e. 0, will be placed at the rightmost place or MSB.

Circular Shift Right

To implement the circular shift right micro-operation, we use the cir symbol.  

For example, R1 -> cir R1.

This command means the 8 bits present in the R1 register will be circular shifted right, and the result will be stored in register R1.

Read about Bitwise Operators in C.

Frequently Asked Questions

What are the Shift micro-operations?

Shift micro-operations are used when the data is stored in registers. These micro-operations are used for the serial transmission of data. The contents of a register can be shifted to the left or the right. There are three types of shift micro-operations- Logical shift, Arithmetic shift and Circular shift.
 

What are different shift micro-operations?

There are three types of shift micro operations: Logical Shift, Arithmetic Shift and Circular Shift. Logical shift transfers zero through serial input. Arithmetic shift micro-operation shifts a signed binary number to the left or to the right position. The circular shift micro operation circulates the bits in the sequence of the register around the both ends.
 

What is logic micro-operation and shift micro-operation?

Logic micro operations operate on individual bits of data. Bit operations through logic micro-operation are useful for making bits-based decisions. Shift micro operation works on serial transfer of information. It may be used in conjunction with logic micro-operation to achieve desired bit manipulations.

Conclusion

To summarise, we studied shift micro-operation and its types in this article. There are three types of shift micro-operation - logical shift, arithmetic shift and circular shift. We went through all these types along with their subtypes.

Recommended Reading:  Data Warehouse Architecture

To learn more about Micro Operations, refer to Arithmetic Micro Operations.

If you want to study more about computer organisation and architecture or micro-operations, you can refer to the Library section of Coding Ninjas.

Till then, Happy Learning Ninja :)

Live masterclass