ScholarQuill logoScholarQuillUniversity Notes
  • Notes
  • Past Papers
  • Blogs
  • Todo
Login
ScholarQuill logoScholarQuillUniversity Notes
Login
NotesPast PapersBlogsTodo
More
SubjectsDiscussionCGPA CalculatorGPA CalculatorStudent PortalCourse Outline
About
About usPrivacy PolicyReportContact
Notes
Past Papers
Blogs
Todo
Analytics
    Current Subject
    🧩
    Computer Organization and Assembly Language
    COMP3137
    Progress0 / 73 topics
    Topics
    1. Introduction to Computer Organization2. Assembly Language3. Comparison of Low-Level and High-Level Languages4. Register Types (16-bit): General Purpose and Special Purpose Registers5. Introduction and Usage of RAM6. Processor7. Registers8. System Bus9. Instruction Execution Cycle10. Assembly and Machine Language11. Assembler12. Linker and Link Libraries13. Programmer's View of a Computer System14. RISC and CISC Architecture15. Physical Address Calculation16. Basic Memory Organization17. CPU Organization18. Top Level View of Computer Function and Interconnection19. Assembler Instruction Cycle20. Execute Cycle21. Interrupts22. Interrupt Cycle23. Memory Connection24. Input/Output Connection25. CPU Connection26. MASM27. MIPS28. Defining Data in MASM Assembler29. Elements of Assembly Language30. Integer Constants31. Integer Expressions32. Real Number Constants33. Character Constants34. String Constants35. Reserved Words36. Identifiers37. Directives38. Instructions39. The NOP (No Operation) Instruction40. Adding and Subtracting Integer41. INC and DEC Instructions42. NEG Instruction43. How to Move Integer Number in Register44. Adding and Subtracting Numbers in Registers45. Declaration and Initialization of Variables46. Moving Data from Variable to Register47. Data Definition Statement48. BYTE and SBYTE Data49. WORD and SWORD Data50. Defining DWORD and SDWORD Data51. Knowledge about Different Data Types52. Operations, Array & Loops53. Division and Multiplication in Assembly54. Jumps Based on Specific Flags55. Jumps Based on Equality56. Simple Jump Statements57. Jumps Based on Specific Condition58. Code Examples59. Practice on MASM60. Procedures61. File Operations Procedures62. Labels in Procedures63. Stack64. Runtime Stack65. Conditional Control Flow Directives66. Compound Expressions67. Data Representation & Conversion68. Architecture69. Data Path70. Control Unit71. Critical Path72. General Principles of Pipelining73. Pipelined Y86 Implementations
    COMP3137›Instruction Execution Cycle
    Computer Organization and Assembly LanguageTopic 9 of 73

    Instruction Execution Cycle

    7 minread
    1,136words
    Intermediatelevel

    Instruction Execution Cycle

    The Instruction Execution Cycle (also called the Machine Cycle) is the sequence of steps that the CPU follows to execute a single instruction in a program. This cycle is fundamental to how a CPU processes instructions and is essential for understanding how a computer runs software.

    The cycle typically consists of multiple phases, each of which corresponds to a specific task needed to fetch, decode, and execute an instruction. This process is repeated for each instruction in a program until the program finishes executing.

    The cycle can be broken down into the following main stages:

    1. Fetch: Retrieve the instruction from memory.
    2. Decode: Interpret the instruction to determine what action to take.
    3. Execute: Perform the operation specified by the instruction.
    4. Store: Optionally, store the result of the operation back into memory or a register.

    Let’s go through each step in more detail:


    1. Fetch

    The fetch phase is the first step in the instruction cycle, where the CPU retrieves the next instruction to be executed from memory (usually RAM).

    Steps in the Fetch Phase:

    • The Program Counter (PC), which holds the address of the next instruction, is used to find the instruction in memory.
    • The CPU sends the address from the Program Counter (PC) to the Memory Address Register (MAR) via the address bus.
    • The memory then sends the instruction located at that address back to the CPU over the data bus.
    • The instruction is placed into the Instruction Register (IR), which holds the instruction to be decoded and executed.
    • After the instruction is fetched, the Program Counter (PC) is updated to point to the next instruction, usually by incrementing the address by the size of the instruction (often 4 bytes for modern architectures).

    Key Components Involved:

    • Program Counter (PC)
    • Memory Address Register (MAR)
    • Data Bus
    • Instruction Register (IR)

    Example:

    • Suppose the PC holds the address 0x2000. The CPU fetches the instruction from memory at address 0x2000, places it into the IR, and increments the PC to 0x2004 (assuming each instruction is 4 bytes long).

    2. Decode

    Once the instruction has been fetched, it must be decoded to determine what the CPU needs to do. During the decode phase, the instruction is analyzed, and the Control Unit (CU) generates the appropriate control signals to carry out the operation specified by the instruction.

    Steps in the Decode Phase:

    • The Instruction Register (IR) holds the fetched instruction, which is typically in machine language (binary).
    • The Control Unit (CU) decodes the instruction by breaking it into its components:
      • The opcode (operation code), which specifies what kind of operation the CPU should perform (e.g., addition, subtraction, load data).
      • The operands, which specify the data or memory locations to be used in the operation.
    • The Control Unit (CU) generates control signals that direct other parts of the CPU to carry out the operation. These control signals can indicate whether to perform an arithmetic operation, access memory, or interact with I/O devices.

    Key Components Involved:

    • Instruction Register (IR)
    • Control Unit (CU)
    • Decoder Logic

    Example:

    • If the instruction is ADD R1, R2, R3, the CU decodes it to:
      • Opcode: ADD (perform an addition)
      • Operands: R1, R2, and R3 (registers where data will be taken from and stored in).

    3. Execute

    The execute phase is where the actual operation specified by the instruction is carried out. Depending on the instruction, this could involve arithmetic or logical operations, memory access, or I/O interactions.

    Steps in the Execute Phase:

    • If the instruction involves an arithmetic or logical operation, the Arithmetic and Logic Unit (ALU) performs the operation.
      • Example: If the instruction is ADD, the ALU will add the values in the specified registers (e.g., R2 and R3), and store the result in R1.
    • If the instruction involves memory access, the CPU either loads data from memory into a register or stores data from a register into memory.
      • Example: If the instruction is MOV R1, 0x1000, the CPU will load data from memory address 0x1000 into R1.
    • If the instruction involves an I/O operation, the CPU communicates with I/O devices to send or receive data.

    Key Components Involved:

    • Arithmetic and Logic Unit (ALU)
    • Registers (e.g., R1, R2, R3)
    • Memory (for load/store operations)

    Example:

    • For the instruction ADD R1, R2, R3, the ALU adds the contents of R2 and R3, and the result is stored in R1.

    4. Store (Optional)

    In the store phase, the result of the execution is either written back to a register or written to memory, depending on the instruction. Not all instructions require a store phase, but many will.

    Steps in the Store Phase:

    • If the instruction modifies a register (like ADD or SUB), the result is placed into the appropriate general-purpose register.
    • If the instruction is a memory store (e.g., STORE), the CPU writes the data to a specific memory address.
    • If the instruction involves an I/O operation, the result may be sent to or received from an I/O device.

    Key Components Involved:

    • Registers
    • Memory (if data needs to be stored)
    • I/O Devices (if involved)

    Example:

    • After executing ADD R1, R2, R3, the result is stored in R1.

    Summary of the Instruction Execution Cycle

    The Instruction Execution Cycle (or Fetch-Decode-Execute Cycle) is a repetitive process that the CPU follows to execute each instruction in a program. Here’s a simplified overview of the cycle:

    1. Fetch: The CPU fetches the instruction from memory using the Program Counter (PC).
    2. Decode: The instruction is decoded to determine the operation and operands, and the appropriate control signals are generated by the Control Unit (CU).
    3. Execute: The CPU executes the operation, which could involve arithmetic, memory access, or I/O operations. The ALU may be used for calculations, and memory or I/O devices may be accessed.
    4. Store: If needed, the result is stored in a register or written back to memory.

    Each step is crucial for the CPU to perform the correct task and move to the next instruction, ensuring that the computer executes programs as expected.


    Instruction Cycle in Modern Processors

    Modern processors often have features like pipelines and superscalar execution that improve the efficiency of the instruction cycle:

    • Pipelining: In a pipeline, different stages of multiple instructions are processed simultaneously. While one instruction is being decoded, another may be fetched, and another may be executed. This increases throughput and reduces overall execution time.
    • Superscalar Execution: Some CPUs can execute multiple instructions at once, utilizing more than one ALU or core to handle different instructions concurrently, further improving performance.

    Despite these optimizations, the basic steps of the instruction execution cycle (fetch, decode, execute, store) remain fundamental to how a processor works.

    Previous topic 8
    System Bus
    Next topic 10
    Assembly and Machine Language

    Past Papers

    Open this section to load past papers

    Click on Show Past Papers to see past papers.
    On This Page
      Reading Stats
      Est. reading time7 min
      Word count1,136
      Code examples0
      DifficultyIntermediate