ScholarQuill logoScholarQuillUniversity Notes
My Semester
Explore Notes
Past Papers12 New
Video CoursesNew
Search
Settings
Study Tools
GPA/CGPA Calculator
Schedule & To-Do
Student Portal
Contact
Contact
ScholarQuill logo
My Semester
Explore Notes
Past Papers12 New
Video CoursesNew
Search
Settings
GPA/CGPA Calculator
Schedule & To-Do
Student Portal
Contact
ScholarQuill logoScholarQuillUniversity Notes
Study PortalCOMP3137Assembler Instruction …
Ctrl + K
Login
Explore
Search
Semester
Papers
CGPA
    COMP3137

    Computer Organization and Assembly Language

    Progress0 / 73 done
    Topics73
    1Introduction to Computer Organization2Assembly Language3Comparison of Low-Level and High-Level Languages
    4General Purpose and Special Purpose Registers5Introduction and Usage of RAM6Processor7Registers8System Bus9Instruction Execution Cycle10Assembly and Machine Language11Assembler12Linker and Link Libraries13Programmer's View of a Computer System14RISC and CISC Architecture15Physical Address Calculation16Basic Memory Organization17CPU Organization18Top Level View of Computer Function and Interconnection19Assembler Instruction Cycle20Execute Cycle21Interrupts22Interrupt Cycle23Memory Connection24Input/Output Connection25CPU Connection26MASM27MIPS28Defining Data in MASM Assembler29Elements of Assembly Language30Integer Constants31Integer Expressions32Real Number Constants33Character Constants34String Constants35Reserved Words36Identifiers37Directives38Instructions39The NOP (No Operation) Instruction40Adding and Subtracting Integer41INC and DEC Instructions42NEG Instruction43How to Move Integer Number in Register44Adding and Subtracting Numbers in Registers45Declaration and Initialization of Variables46Moving Data from Variable to Register47Data Definition Statement48BYTE and SBYTE Data49WORD and SWORD Data50Defining DWORD and SDWORD Data51Knowledge about Different Data Types52Operations, Array & Loops53Division and Multiplication in Assembly54Jumps Based on Specific Flags55Jumps Based on Equality56Simple Jump Statements57Jumps Based on Specific Condition58Code Examples59Practice on MASM60Procedures61File Operations Procedures62Labels in Procedures63Stack64Runtime Stack65Conditional Control Flow Directives66Compound Expressions67Data Representation & Conversion68Architecture69Data Path70Control Unit71Critical Path72General Principles of Pipelining73Pipelined Y86 Implementations
    7 min read
    Topic 19 of 73
    Topic Study Note Illustration
    19

    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...

    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 view and download past papers

    Click on Show Past Papers to load available exam papers.

    Reading Progress
    0%
    7mremaining
    1.2kwords
    Intermediatelevel
    On This Page

    No headings found

    Study Toolkit

    Subject Portal

    Computer Organization and Assembly Language