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›Elements of Assembly Language
    Computer Organization and Assembly LanguageTopic 29 of 73

    Elements of Assembly Language

    7 minread
    1,166words
    Intermediatelevel

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

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