StudentCodingHUB

Use programming to create innovative things.
  • new post

    Friday, 20 March 2015

    What are the Steps to Execute an Instruction

    What are the Steps to Execute an Instruction?

    The main purpose of a CPU is to execute instructions. The CPU executes the binary representation of the instructions, i.e., machine code.
    Since programs can be very large, and since CPUs have limited memory, programs are stored in memory (RAM). However, CPUs do its processing on the CPU. So, the CPU must copy the instruction from memory to the CPU, and once it's in the CPU, it can execute it.

    The PC is used to determine which instruction is executed, and based on this execution, the PC is updated accordingly to the next instruction to be run.
    Essentially, a CPU repeatedly fetches instructions and executes them.

    The following is a summary of the six steps used to execute a single instruction.

    Step
    Description
    1
    Fetch Instruction from Memory
    2
    Decode Instruction and Fetch Operands
    3
    Perform ALU Operations
    4
    Memory Access (for load/store)
    5
    Store ALU result to register file
    6
    Update PC
    These are the six steps to executing an instruction. Not every instruction goes through every step. However, we label each step so that you can be aware they exist.
    Some of these steps may not make much sense now, but hopefully, they're be clearer once we start implementing the steps in depth.

    The major computer system components (processor, main memory, I/O modules) need to be interconnected in order to exchange data and control signals. The most popular means on interconnection is the use of a shared system bus consisting on multiple lines. 

    A computer can be programmed by using a small set of basic logic components that store binary data and perform arithmetic and logical operations on data. If a particular computation is to be performed, a configuration of logic components designed specifically for that computation could be constructed. 

    Programming in hardware is termed a hardwired program. This customized hardware system accepts data and produces results. This customized hardware system is not very flexible because for each new program, this customized hardware must be rewired. 

    The entire program is actually a sequence of steps. At each step, some arithmetic or logic operation is performed on some data. For each step, a new set of control signals is needed. Simply provide a unique code for each possible set of control signals, and add to the general-purpose hardware a segment that can accept a code and generate control signals.

     Programming is now much easier. Instead of rewiring the hardware for each new program, simply provide a new sequence of codes. Each code is, in effect, an instruction, and part of the hardware interprets each instruction and generates control signals. 

    To distinguish this new method of programming, a sequence of codes or instructions is called software (micro program). The CPU exchanges data with memory. The CPU typically makes use of two internal registers: a memory address register (MAR), which specifies the address in memory for the next read or write, and a memory data register (MDR), which contains the data to be written into memory or receives the data read from memory.

    Instruction cycle The basic function performed by a computer is execution of a program, which consists of a set of instructions stored in memory. The processor does the actual work by executing instructions specified in the program. In the simplest form, instruction processing consists of two steps: the processor reads (fetches) instructions from memory one at a time and executes each instruction. The processing required for a single instruction is called an instruction cycle. 

    An instruction cycle is shown below: Program execution halts only if the machine is turned off, some sort of unrecoverable error occurs, or a program instruction that halts the computer is encountered. 

    Instruction Fetch and Execute 
    • The processor fetches an instruction from memory – program counter (PC) register holds the address of the instruction to be fetched next 
    • The processor increments the PC after each instruction fetch so that it will fetch the next instruction in the sequence – unless told otherwise 
    • The fetched instruction is loaded into the instruction register (IR) in the processor – the instruction contains bits that specify the action the processor will take
    • The processor interprets the instruction and performs the required action In general, these actions fall into four categories:
    • Processor-memory – data transferred to or from the processor to memory 
    • Processor-I/O – data transferred to or from a peripheral device by transferring between the processor and an I/O module 
    • Data processing – the processor performs some arithmetic or logic operation on data 
    • Control – an instruction may specify that the sequence of execution be altered An instruction execution may involve a combination of these actions. 

    No comments:

    Post a Comment