What is Machine Cycle? Types, Examples & More

What is Machine Cycle?

Machine cycle refers to the steps performed by the processor of the computer to execute an instruction after it is received and consists of T states.

Technically, it refers to the time taken by the processor to complete a single operation which involves accessing I/O, memory, or acknowledging a peripheral request.

KEY TAKEAWAYS

  • The machine cycle is the basic process of a computer that involves fetching, reading and interpreting an instruction, changing it into machine language and executing and storing the code.
  • These cycles consist of 3 to 6 T states that refer to the subdivision of the completed process in a single clock period.
  • Machine cycle determines the performance speed and level of the computer system and does not let any of them fall.
  • There are a lot of different cycles performed by the computer right from the moment it is switched on till it is switched off.
  • The components that are usually involved in a machine cycle are the CPU and the memory unit.

Understanding Machine Cycle

What is Machine Cycle

Machine cycle is the most fundamental operation performed by a computer system to carry out an instruction.

It is the basic operation of the processor that involves reading or writing a single byte from the I/O port or to the memory, respectively.

Ideally, there are lots of these cycles performed by the processor of the computer to perform tedious tasks such as displaying a single character on the monitor and others.

And these cycles start from the moment you switch on your computer system and carry on till you shut it down.

Typically, modern computer processors can carry out millions of machine cycles per second.

The machine cycle process involves four basic steps such as fetch, decode, execute and store, and accordingly, it is known by different names such as:

  • E-cycle or Execution cycle
  • I-cycle or Instruction cycle
  • Fetch-decode-execute cycle and
  • Fetch-execute cycle.

Though basic, attempts are made to improve the machine cycle process and one such way is by using pipelining.

With its implementation, modern computers do not have to wait until an instruction completes all four steps to start working on the following instruction, as was the case with the earlier computer systems.

With pipelining, the processor can start fetching the second instruction before the previous machine cycle is completed.

Machine cycle plays a significant role. It basically maintains the flow of instructions and their execution so that they do not give any wrong results.

It helps with the better understanding of the internals of the instruction execution so that any need for further improvements can be figured out.

In short, the machine cycle determines the performance of the computer system on the whole and prevents it from being degraded.

Read Also:  What is Virtual Real Mode? (Explained)

It also helps in determining the processing speed of the device based on the number of instructions executed in a given period of time.

Machine Cycle Types

The first machine cycle is the opcode fetch cycle which is followed by memory read and write cycles, I/O read and write cycles, interrupt acknowledge and bus idle.

Different types of operations are performed in these different types of machine cycles, making each of them significant for the entire process. Here they are all explained for you:

Opcode Fetch Cycle:

Here, the nature of the instructions to be carried out is found out. The Program Counter contents are placed on the address bus and the opcode is read.

This cycle has variable lengths ranging from 4 to 6 T states. Depending on the instructions, the states can be as follows:

  • In T1 state, PC contents are placed on the address bus and status signals are sent
  • In T2 state, low-order address withdraws and RD low signal is sent to enable the location of the addressed memory
  • In T3 state, data is loaded from the data bus to the instruction register and RD is raised to high to disable memory device
  • In T4 state, the processor decodes the opcode and decides whether to enter the following state or go back to T1
  • In T5 and T6 state, internal processor operations such as stack write are performed.

Memory Read Cycle:

Here, the content of ROM or R/W memory is read and has three states as follows:

  • In T1 state, the processor places the memory address on the address bus from the Program Counter, stack pointer, or general purpose register and ALE and status signals are also activated
  • In T2 state, RD signal low is sent to enable the location of the addressed memory and the memory device places the contents of it on the data bus and
  • In T3 state, data from the data bus is loaded in the specific register and RD is raised to high to disable the memory device.

Memory Write Cycle:

Here, the data is stored into the stack memory or data memory in three states. These states are similar to the above with the only exception that in the T2 state, WR signal low is sent for writing in the memory location.

When it is high, it disables the memory device and the write operation is concluded.

I/O Read and I/O Write Cycles:

These cycles are similar to the memory read and write machine cycles with the difference that the IO/M signal is high to indicate that it is an I/O operation.

Interrupt Acknowledge Cycle:

In this cycle, instruction from the external devices is read according to the signal and is almost similar to the opcode fetch cycle for RST instruction with a slight difference such as:

  • In place of the RD signal, the INTA signal is activated and
  • In place of 011, the status lines are 111.

And, for CALL instructions, two bytes of the CALL address are fetched through two extra interrupt acknowledge machine cycles.

Read Also:  What is Pipeline Flushing? (Explained)

Bus Idle Cycle:

Here, the machine cycle is not Read or Write and is akin to memory read cycles but the ALE and RD signals are not set off.

Machine Cycle Examples

An example of a complete machine cycle and its steps can be solving a math problem.

The entire cycle includes:

  • The users of the computer entering a math problem using the input devices
  • This problem is stored in the memory
  • The computer fetches this instruction from the memory
  • The control unit decodes it into machine instructions that the computer can understand
  • The Arithmetic Logic Unit or ALU carries out the instructions to find the answer to the math problem
  • The result is sent and stored in the memory
  • It is accessed by the processor when the user instructs and
  • It is displayed finally on the computer screen.

Machine Cycle Steps

Typically, one machine cycle is completed by performing four steps namely, fetch, decode, execute and store.

The functions performed in these different steps are:

  • Fetch – In this step an instruction is fetched from the memory
  • Decode – In this step the instruction retrieved from the memory in the above step is translated into machine commands
  • Execute – In this step the computer commands are carried out according to the given instructions and
  • Store – In this final step, the results of the execution are sent back and written in the memory.

What is Machine Cycle State?

The states in a machine cycle, called T states, refer to the part of the cycle that is completed in one single internal clock pulse. It is actually one time period of frequency of the processor.

There is also a wait state that a processor enters into during a machine cycle.

T states:

In simple words, it is the time taken by the processor to complete the process of accessing the memory or the I/O devices.

These T states are typically measured from the falling edge of a single clock pulse to the following clock pulse. This measure may vary depending on the maximum clock frequency of the processor.

Wait states:

Apart from the T state, there is also the concept of wait states in a few specific processors such as 8085.

This is something that happens in a few specific applications where the timing of the processor does not match the speed of the I/O system or the memory system. This means that it takes a longer time to read or write data.

In such circumstances, the processor will first have to confirm whether or not a peripheral device is ready to move data.

If the pin is READY, in other words, if it is high, data transfer will happen. Otherwise, the processor will enter into a wait state during the machine cycle.

This wait state will keep on being inserted as long as READY is low and during this state all the contents of the data bus, control bus and address bus will be held constant.

Read Also:  What is Out-of-Order Execution? (Explained)

An additional clock cycle time is given to the I/O port or addressed memory by the wait state so that it can yield legitimate data on the data bus.

This characteristic allows using I/O devices and memory that may have extended access times.

How Many States are there in the Machine Cycle?

Every part of the machine cycle may consist of 3 to 6 T states, also referred to as clock cycles or clock periods wherein the fetch cycle has four T states and the execution cycle has three of these states. Along with others, there can be as many as 13 T states in total.

The breakup of these states is as follows:

  • One opcode fetch – 4 T states
  • Two memory read – 3 T states each and
  • One memory write – 3 T states.

Machine Cycle Vs Instruction Cycle

  • The time taken by the processor to complete an operation of accessing I/O devices or memory is called a machine cycle, but instruction cycle typically refers to the steps followed by the processor to fetch and execute any instruction
  • A machine cycle refers to the steps performed by a CPU to get all the instructions implemented and executed while an instruction cycle defines the computer taking an instruction given by a program and then understanding and executing the same from the memory
  • The four main steps followed in a machine cycle are called fetch, decode, execute and store but for an instruction cycle the first three are called the same while the fourth is called run
  • Only one machine cycle defines the time taken by a particular instruction to execute from start to finish but there can be several instruction cycles running on a computer system at the same time
  • Machine cycle is typically not used in the realistic environments as opposed to instruction cycles that are used in such settings and spoken and understood by the specialists and
  • The components that facilitate a machine cycle are the memory unit and the Central Processing Unit but instruction cycle is facilitated by the Arithmetic Logic Unit or ALU, data, memory and the registers.

Conclusion

The machine cycle is the process of executing an instruction by a computer in four easy steps that involves fetching, decoding, executing, and storing.

The machine cycle of a computer is not only important for it to perform, but it also helps in calculating the performance of the processor and selecting the device.