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›Assembler Instruction Cycle
    Computer Organization and Assembly LanguageTopic 19 of 73

    Assembler Instruction Cycle

    7 minread
    1,214words
    Intermediatelevel

    Assembler Instruction Cycle

    The assembler instruction cycle refers to the process that occurs during the execution of an instruction in a computer system. This cycle is essential for translating high-level commands into machine-level operations that can be executed by the CPU. The instruction cycle is the heart of the processor’s activity, enabling it to perform operations step-by-step.

    In the context of assembly language programming, the instruction cycle is crucial because the CPU fetches, decodes, and executes assembly language instructions (which are translated into machine code by an assembler).

    The instruction cycle can be broken down into a series of stages. These stages involve both the CPU's internal operations and memory operations to fetch and execute an instruction. Let's go through these steps in detail:


    Stages of the Instruction Cycle

    The instruction cycle is typically divided into several stages:

    1. Fetch
    2. Decode
    3. Execute
    4. Store (or Write Back)

    These stages repeat continuously for each instruction in a program.


    1. Fetch Stage

    The first step in the instruction cycle is the fetching of an instruction from memory. The Program Counter (PC) holds the address of the next instruction to be fetched.

    • Action: The CPU sends the address stored in the PC to the memory (RAM) via the address bus.
    • Memory: The instruction stored at that memory address is transferred back to the Instruction Register (IR).
    • Program Counter Update: After fetching the instruction, the PC is updated to point to the next instruction in memory (usually by incrementing the PC).

    Key Points:

    • The PC keeps track of where the next instruction is located in memory.
    • The instruction is fetched from the main memory (RAM) and placed into the IR (Instruction Register).

    2. Decode Stage

    In this stage, the CPU decodes the fetched instruction to understand what action it needs to perform. The Control Unit (CU) is responsible for interpreting the instruction and determining what type of operation should be performed.

    • Action: The instruction stored in the Instruction Register (IR) is decoded by the Control Unit (CU).

    • Interpretation: The instruction is broken down into its components (e.g., operation code (opcode), operands, addressing mode).

      • The opcode specifies the operation (e.g., ADD, SUB, MOV).
      • The operands represent the data or addresses involved in the operation.
      • The addressing mode specifies how to access the data.
    • Control Signals: Based on the decoded instruction, the Control Unit (CU) generates appropriate control signals to manage data movement, memory access, and other operations.

    Key Points:

    • The Control Unit (CU) interprets the instruction in the IR.
    • The CPU determines the operation to be performed, where the operands are located, and how to execute the instruction.

    3. Execute Stage

    Once the instruction is decoded, the CPU proceeds to execute it. The ALU (Arithmetic Logic Unit) typically performs this stage, which involves the actual computation or data manipulation specified by the instruction.

    • Action: The operands (which could be data from memory, registers, or immediate values) are processed according to the instruction.

      • For example, if the instruction is an addition (e.g., ADD), the ALU will add the two operands.
      • If the instruction involves memory access (e.g., a load or store), the CPU will perform the appropriate memory read/write operations.
    • Execution: Depending on the instruction type:

      • Arithmetic/Logical Operations: The ALU performs arithmetic (addition, subtraction) or logical (AND, OR) operations.
      • Memory Access: The CPU may read data from or write data to memory.
      • Control Transfer: If the instruction involves a jump (like in a conditional branch or loop), the Program Counter (PC) may be updated to a new value based on the result of the operation.

    Key Points:

    • The ALU performs the arithmetic or logical operation (e.g., addition, subtraction).
    • Data may be read from or written to memory, or registers may be updated.

    4. Store / Write Back Stage

    In some instructions, especially those that involve computation or manipulation of data, the result of the execution must be stored or written back to memory or a register.

    • Action: After execution, the result is written back to memory (for load/store operations) or to a register (for register-based operations).

      • Write to Memory: If the instruction involves writing to memory (e.g., a store instruction), the result of the operation is written back to the specified memory location.
      • Write to Register: If the instruction involves updating a register (e.g., moving a value to a register), the result is written to the appropriate register.
    • Update Program Counter (PC): After this stage, the PC is updated again (if needed) to point to the next instruction to be executed.

    Key Points:

    • Results are written back to the memory or registers.
    • The Program Counter (PC) is updated for the next instruction.

    Instruction Cycle Summary

    The basic instruction cycle follows these steps:

    1. Fetch: Get the instruction from memory using the address in the Program Counter (PC).
    2. Decode: Decode the instruction to understand what action needs to be taken.
    3. Execute: Perform the required computation or data manipulation.
    4. Store/Write Back: Store the result back to memory or registers, and update the Program Counter (PC).

    This cycle repeats for each instruction in the program, with the CPU continually fetching, decoding, executing, and writing results back, allowing it to carry out complex operations.


    Assembler's Role in the Instruction Cycle

    The assembler plays an important role in preparing the instructions for the CPU. It translates assembly language (which is human-readable) into machine language (binary code) that the CPU can understand. The assembler does this by converting each assembly language instruction into its corresponding machine code.

    • Assembler Translation: Assembly instructions like MOV, ADD, SUB, etc., are translated by the assembler into machine opcodes.
    • Memory Addressing: The assembler assigns memory addresses to labels and variables, which are used by the CPU during execution.

    Thus, while the instruction cycle describes what happens inside the CPU, the assembler ensures that the code is in a form that the CPU can understand and execute.


    Example of the Instruction Cycle (Assembly Instruction)

    Let’s look at a simple example where the CPU executes an assembly instruction like ADD:

    Instruction: ADD R1, R2, R3

    This instruction means "Add the contents of registers R2 and R3, and store the result in register R1".

    1. Fetch:

      • The CPU fetches the instruction ADD R1, R2, R3 from memory.
      • The Program Counter (PC) points to the memory address of this instruction.
    2. Decode:

      • The Control Unit (CU) decodes the instruction and determines that the ALU needs to add the values in registers R2 and R3, and store the result in R1.
    3. Execute:

      • The ALU adds the values in R2 and R3.
    4. Store/Write Back:

      • The result of the addition is written to R1.
      • The Program Counter (PC) is updated to point to the next instruction.

    Conclusion

    The assembler instruction cycle is a fundamental process in which a CPU executes machine-level instructions. It involves the following key stages: fetching the instruction, decoding it, executing the specified operation, and storing the result back into memory or registers.

    The assembler prepares assembly instructions by translating them into machine code, allowing the CPU to perform these cycles. This cycle repeats continuously during the execution of a program, enabling the computer to perform complex tasks efficiently.

    Previous topic 18
    Top Level View of Computer Function and Interconnection
    Next topic 20
    Execute Cycle

    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,214
      Code examples0
      DifficultyIntermediate