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›Instructions
    Computer Organization and Assembly LanguageTopic 38 of 73

    Instructions

    7 minread
    1,109words
    Intermediatelevel

    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

    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 load past papers

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