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 PortalCOMP3137Elements Assembly Lang…
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 29 of 73
    Topic Study Note Illustration
    29

    Elements of Assembly Language

    Assembly language is a low-level programming language that provides a symbolic representation of a computer's machine code instructions. It allows programmers to write programs that are very...

    Elements of Assembly Language

    Assembly language is a low-level programming language that provides a symbolic representation of a computer's machine code instructions. It allows programmers to write programs that are very close to the hardware level, giving them direct control over the computer’s operations.

    In an assembly language program, there are several key elements that define how the program is written and executed. Below is a breakdown of the main elements of assembly language:


    1. Mnemonics (Instructions)

    Mnemonics are symbolic representations of machine-level instructions. These are the core of an assembly language program and correspond to specific machine instructions that the CPU can execute.

    • For example:
      • MOV: Move data between registers or between a register and memory.
      • ADD: Add two operands.
      • SUB: Subtract two operands.
      • MUL: Multiply two operands.
      • JMP: Jump to a specific instruction (used for loops or branching).
      • CMP: Compare two values.

    Example:

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

    2. Registers

    Registers are small, fast storage locations within the CPU. They are used to store data, addresses, or control information temporarily during the execution of a program. Each processor has its own set of registers, but there are some common types of registers used in most assembly languages.

    Common Register Types:

    • General-purpose registers (e.g., AX, BX, CX, DX): Used for storing temporary data during execution.
    • Index registers (e.g., SI, DI): Used for addressing data in memory.
    • Pointer registers (e.g., SP, BP): Used for stack management.
    • Flag registers (e.g., FLAGS): Store status flags (such as carry, zero, sign, etc.) that indicate the result of an operation.

    Example:

    MOV AX, 100   ; Load 100 into the AX register
    MOV BX, 50    ; Load 50 into the BX register
    ADD AX, BX    ; Add BX to AX, result is stored in AX
    

    3. Labels

    Labels are used as markers to indicate specific locations in your program. They are often used for branching (e.g., loops and jumps). Labels are not instructions, but they provide a way for the program to "jump" to different sections based on conditions.

    Example:

    start:  ; This is a label
        MOV AX, 5
        ADD AX, 3
        JMP start  ; Jump back to the 'start' label (infinite loop)
    

    4. Directives (Pseudo-Op Codes)

    Directives are special commands that tell the assembler how to process the assembly code. They are not executed by the CPU but are essential for organizing and managing your program’s memory and execution.

    Common Directives:

    • .data: Marks the beginning of the data segment, where data is defined.
    • .text: Marks the beginning of the code segment, where executable instructions are written.
    • .bss: Defines a section for uninitialized variables.
    • .org: Defines the starting address for code or data in memory.
    • .equ: Defines a constant or symbol.
    • .db, .dw, .dd: Reserve space for bytes, words, or double words of data.
    • .end: Marks the end of the source code.

    Example:

    .data
    message DB 'Hello, World!', 0   ; Declare a string
    num1 DW 1234                    ; Declare a word-sized variable
    
    .text
    ; Code goes here...
    

    5. Constants

    Constants are values that are predefined and do not change during the execution of the program. In assembly language, constants are often defined using EQU (equate) directive or can be hardcoded into the program.

    Example:

    MAX_VALUE EQU 100   ; Define a constant named MAX_VALUE with a value of 100
    

    Constants are typically used in situations where a specific value must be reused throughout the program.


    6. Memory Addressing

    Memory addressing refers to how data is accessed from memory. In assembly language, there are several addressing modes that dictate how operands are accessed.

    Common Addressing Modes:

    • Immediate addressing: The operand is a constant value directly used in the instruction.
      MOV AX, 5  ; 5 is the immediate value
      
    • Register addressing: The operand is stored in a register.
      MOV AX, BX  ; Copy the value of BX into AX
      
    • Direct addressing: The operand is accessed from a specific memory address.
      MOV AX, [1000h]  ; Load the value at memory address 1000h into AX
      
    • Indirect addressing: The operand is accessed from a memory address stored in a register.
      MOV AX, [BX]  ; Load the value at the memory address in BX into AX
      
    • Indexed addressing: Combines a base address and an index (usually a register).
      MOV AX, [SI + 4]  ; Load the value at the memory address (SI + 4) into AX
      

    7. Comments

    Comments are used to add descriptive notes within the code. These do not affect the execution of the program, but they help explain what the code is doing. In assembly language, comments are typically denoted by a semicolon (;).

    Example:

    MOV AX, 5     ; Load the value 5 into register AX
    ADD AX, 10    ; Add 10 to AX
    

    Everything after the semicolon on that line is treated as a comment.


    8. Control Flow (Jumping, Branching)

    Assembly language programs often include control flow instructions that alter the normal sequence of execution. These include conditional and unconditional jumps (branches), which allow loops and conditional operations.

    Common Jump Instructions:

    • JMP: Unconditional jump to a specific label.
    • JE / JZ: Jump if equal or zero (based on a flag).
    • JNE / JNZ: Jump if not equal or not zero.
    • JG / JNLE: Jump if greater.
    • JL / JNGE: Jump if less.

    Example:

    CMP AX, BX      ; Compare AX with BX
    JE equalLabel   ; Jump to 'equalLabel' if AX == BX
    JMP notEqual    ; Jump to 'notEqual' otherwise
    

    9. Subroutines (Functions)

    In assembly language, subroutines (or functions) are defined as a series of instructions that can be called from different parts of the program. A subroutine is typically entered via a CALL instruction, and the return is done using the RET instruction.

    Example:

    ; Subroutine definition
    myFunction:
        MOV AX, 100     ; Perform some task
        RET             ; Return from the subroutine
    
    ; Calling the subroutine
    CALL myFunction  ; Call 'myFunction' subroutine
    

    10. Input/Output Operations

    Input and output operations are handled by interacting with the operating system or hardware through specific instructions or system calls. In assembly language, this is usually done using interrupts.

    Example (for DOS):

    MOV AH, 09h      ; DOS interrupt to print string
    LEA DX, message  ; Load address of the string into DX
    INT 21h          ; Call DOS interrupt to print the string
    

    Conclusion

    The elements of assembly language—such as mnemonics, registers, labels, directives, constants, memory addressing modes, comments, control flow, subroutines, and I/O operations—form the building blocks for writing programs that can directly control hardware. While assembly language is low-level and machine-specific, it offers maximum control over system resources, making it useful in systems programming, embedded systems, and performance-critical applications. Understanding these elements helps programmers to write efficient, optimized, and hardware-near code.

    ← Previous topic 28
    Defining Data in MASM Assembler
    Next topic 30 →
    Integer Constants

    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