Program Execution in a Computer

Roodra Mohan
3 min readJul 12, 2021

--

Following article describes how the operations gets executed in a computer. It also gives the description of all the processors registers which are used in the operation execution.

The Von Neumann Architecture of a computer comprise of the following five units :

1.A processing unit that contains an arithmetic logic unit(ALU) and processor registers.
2.A control unit that contains an instruction register and program counter.
3.Memory that stores data and instructions(Generally RAM or Cache).
4.External mass storage for permanently storing the data.
5.Input and output mechanisms.

The above units are utilized by the computer to execute operations. The operations of a computer can be summarized as follows:

1. The computer accepts information in the form of programs and data through an input unit and stores it in the memory.
2. Information stored in the memory is fetched under program control, into an arithmetic and logic unit(which is a part of processing unit) where it is processed.
3. Processed information leaves the computer through an output unit.
4. All activities inside the machine are directed by the control unit.

Before diving into the process of execution of operations we must have a fair idea about all the processors registers. In addition to ALU, CPU contains a number of registers.

1. The Instruction Register(IR) holds the instruction that is currently being executed. Its output is available to the control circuit.
2. Control circuit produces the timing signals that control the various processing elements involved in executing the instruction.
3. The Program Counter (PC) is another specialized register. It keeps track of the execution of the program. It contains the memory address of the next instruction. During the execution of an instruction, the contents of the PC are updated to correspond to the address of the next instruction to be executed.

NOTE : Execution of the program starts when the PC is set to point to the first instruction of the program.

4. Besides IR and PC processor has n general purpose registers R0 through R(n-1).
5. Memory Address Register(MAR) and Memory Data Register(MDR) facilitate communication with the memory.
a) MAR : It holds the address of the location to be accessed.
b) MDR : It contains the data to be written into or read out of the addressed location.

The Process :

Execution of the program starts when the PC is set to point to the first instruction of the program. The contents of the PC are transferred to the MAR and a read control signal is sent to the memory.

After the time required to access the memory is elapsed the addressed word (in this case the first instruction of the program) is read out of the memory and loaded into the MDR. Next, the contents of the MDR are transferred to the IR. At this point, the instruction is ready to be decoded and executed.

If the instruction involves an operation to be performed by the ALU, it is necessary to obtain the required operands. If an operand resides in the memory (it could also be in a general-purpose register in the processor) it has to be fetched by sending its address to the MAR and initiating a read cycle.

When the operand has been read from the memory into the MDR, it is transferred from the MDR to the ALU. After one or more operands are fetched in this way, the ALU can perform the desired operation.

If the result of the operation is to be stored in the memory then the result is sent to the MDR. The address of the location where the result is to be stored is sent to the MAR, and a write cycle is initiated. At some point during the execution of the current instruction the contents of the PC are incremented so that the PC points to the next instruction to be executed.

If the result of the operation is to be stored in the memory then the result is sent to the MDR. The address of the location where the result is to be stored is sent to the MAR, and a write cycle is initiated. At some point during the execution of the current instruction the contents of the PC are incremented so that the PC points to the next instruction to be executed.

--

--