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 PortalCOMP3137Instructions
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 38 of 73
    Topic Study Note Illustration
    38

    Instructions

    In assembly language, instructions are the core operations that a CPU performs. Each instruction represents a single operation, such as moving data, performing arithmetic, controlling program flow,...

    Instructions in Assembly Language

    In assembly language, instructions are the core operations that a CPU performs. Each instruction represents a single operation, such as moving data, performing arithmetic, controlling program flow, or interacting with memory or I/O devices. These instructions are encoded in machine language and executed directly by the processor.

    Assembly instructions are often specific to the processor architecture (e.g., x86, ARM, MIPS), and each architecture has its own set of supported instructions, known as its instruction set architecture (ISA).

    In this explanation, we'll cover the types of assembly instructions, how they are structured, and some common examples.

    1. Basic Structure of an Instruction

    An assembly instruction generally consists of:

    • Opcode (Operation Code): The operation to be performed (e.g., move, add, jump).
    • Operands: The data or registers on which the operation is to be performed (e.g., registers, memory addresses, immediate values).

    Syntax:

    opcode operand1, operand2, ...
    

    For example:

        MOV AX, 5    ; Move the value 5 into register AX
        ADD BX, 3    ; Add 3 to the value in register BX
    

    2. Categories of Assembly Instructions

    Instructions in assembly can be categorized into several broad types based on the operation they perform. Common categories include:

    1. Data Movement Instructions
    2. Arithmetic Instructions
    3. Logic Instructions
    4. Control Flow Instructions
    5. Stack Instructions
    6. I/O Instructions
    7. Special Purpose Instructions

    3. Data Movement Instructions

    Data movement instructions are used to move data between registers, memory, and I/O devices.

    3.1. MOV (Move)

    • Purpose: Copies data from one location (register, memory, or immediate value) to another location.
    • Syntax: MOV destination, source

    Example:

        MOV AX, 10   ; Move the immediate value 10 into the AX register
        MOV BX, AX   ; Move the value from AX into BX
    

    3.2. PUSH and POP

    • Purpose: PUSH saves a value to the stack, and POP retrieves a value from the stack.
    • Syntax:
      • PUSH operand
      • POP operand

    Example:

        PUSH AX     ; Push the value in AX onto the stack
        POP BX      ; Pop the value from the stack into BX
    

    3.3. LEA (Load Effective Address)

    • Purpose: Loads the address of a variable into a register.
    • Syntax: LEA destination, source

    Example:

        LEA SI, var  ; Load the address of 'var' into register SI
    

    4. Arithmetic Instructions

    These instructions perform mathematical operations such as addition, subtraction, multiplication, and division.

    4.1. ADD (Add)

    • Purpose: Adds two operands (usually registers or an immediate value).
    • Syntax: ADD destination, source

    Example:

        ADD AX, BX   ; Add the value in BX to AX
    

    4.2. SUB (Subtract)

    • Purpose: Subtracts one operand from another.
    • Syntax: SUB destination, source

    Example:

        SUB AX, 5    ; Subtract 5 from the value in AX
    

    4.3. MUL and IMUL (Multiply)

    • Purpose: Performs multiplication. MUL is for unsigned multiplication, and IMUL is for signed multiplication.
    • Syntax:
      • MUL operand
      • IMUL operand

    Example:

        IMUL AX, BX   ; Multiply AX by BX (signed multiplication)
    

    4.4. DIV and IDIV (Divide)

    • Purpose: Performs division. DIV is for unsigned division, and IDIV is for signed division.
    • Syntax:
      • DIV operand
      • IDIV operand

    Example:

        IDIV BX   ; Divide AX by BX (signed division, quotient in AL, remainder in AH)
    

    5. Logic Instructions

    These instructions perform logical operations, such as AND, OR, XOR, and NOT.

    5.1. AND (Logical AND)

    • Purpose: Performs a bitwise AND operation between two operands.
    • Syntax: AND destination, source

    Example:

        AND AX, 1    ; Perform a bitwise AND between AX and 1
    

    5.2. OR (Logical OR)

    • Purpose: Performs a bitwise OR operation between two operands.
    • Syntax: OR destination, source

    Example:

        OR AX, BX    ; Perform a bitwise OR between AX and BX
    

    5.3. XOR (Logical XOR)

    • Purpose: Performs a bitwise XOR (exclusive OR) operation between two operands.
    • Syntax: XOR destination, source

    Example:

        XOR AX, AX   ; Clear the AX register (AX = 0)
    

    5.4. NOT (Logical NOT)

    • Purpose: Performs a bitwise NOT operation, flipping all bits of the operand.
    • Syntax: NOT operand

    Example:

        NOT AX   ; Inverts the bits in AX
    

    6. Control Flow Instructions

    These instructions alter the flow of execution in a program. They are used for looping, branching, and handling conditional logic.

    6.1. JMP (Jump)

    • Purpose: Unconditionally jumps to another part of the program (i.e., jumps to a label).
    • Syntax: JMP label

    Example:

        JMP end   ; Jump to the label 'end'
    

    6.2. JE, JNE, JG, JL (Conditional Jumps)

    • Purpose: These are conditional jump instructions that jump based on the state of the flags in the CPU (e.g., zero, carry, sign).
      • JE: Jump if equal (ZF=1)
      • JNE: Jump if not equal (ZF=0)
      • JG: Jump if greater (SF=OF)
      • JL: Jump if less (SF≠OF)

    Example:

        JE equalLabel  ; Jump to 'equalLabel' if the zero flag is set (i.e., equality)
    

    6.3. CALL and RET (Call and Return)

    • Purpose: CALL is used to call a function, and RET is used to return from a function.
    • Syntax:
      • CALL function
      • RET

    Example:

        CALL myFunction   ; Call a function
        RET               ; Return from function
    

    7. Stack Instructions

    Stack (abstract data type)
    Visual ReferenceStack (Abstract Data Type)
    Wikipedia

    These instructions manage the stack, which is used for storing temporary data like function parameters, return addresses, and local variables.

    7.1. PUSH and POP

    • Purpose: These instructions save or retrieve data from the stack.

    Example:

        PUSH AX   ; Push AX onto the stack
        POP BX    ; Pop a value from the stack into BX
    

    7.2. CALL and RET

    • Purpose: The CALL instruction pushes the return address onto the stack and then jumps to a function, while RET pops the return address from the stack and jumps back to the calling function.

    Example:

        CALL MyFunction  ; Push return address and call MyFunction
        RET              ; Pop return address and return from function
    

    8. I/O Instructions

    These instructions interact with input and output devices, such as reading from the keyboard or writing to the screen.

    8.1. IN and OUT

    • Purpose: These instructions are used for input and output operations, typically with hardware ports.
    • Syntax:
      • IN destination, port
      • OUT port, source

    Example:

        IN AL, 60h   ; Input from port 60h (keyboard)
        OUT 60h, AL  ; Output to port 60h (keyboard)
    

    9. Special Purpose Instructions

    These instructions control CPU-specific features, such as flags, segmentation, or system calls.

    9.1. NOP (No Operation)

    • Purpose: Does nothing. Often used for timing or as placeholders in code.

    Example:

        NOP  ; Do nothing
    

    9.2. HLT (Halt)

    • Purpose: Stops the program's execution and halts the CPU.

    Example:

        HLT  ; Halt the program
    

    Conclusion

    Assembly instructions are the fundamental operations that control a computer’s behavior at the lowest level. They can perform data movement, arithmetic, logic, control flow, stack operations, and I/O operations. Understanding how to use these instructions is crucial for

    ← Previous topic 37
    Directives
    Next topic 39 →
    The NOP (No Operation) Instruction

    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.1kwords
    Intermediatelevel
    On This Page

    No headings found

    Study Toolkit

    Subject Portal

    Computer Organization and Assembly Language