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

    Identifiers

    7 minread
    1,143words
    Intermediatelevel

    Identifiers in Assembly Language

    In assembly language, identifiers are names given to various elements in a program, such as variables, labels, functions, registers, or other entities. Identifiers allow the programmer to refer to data or instructions in a meaningful and readable way. Since assembly language is a low-level programming language, identifiers are essential for making the code more understandable and easier to maintain.

    Key Characteristics of Identifiers

    1. Naming Rules: Identifiers in assembly must follow specific rules about what characters are allowed and how long they can be. These rules vary slightly depending on the assembler (e.g., MASM, NASM, or GAS).
    2. Purpose: Identifiers are used to name data, code locations (labels), and sometimes constants or macros.
    3. No Reserved Words: Identifiers cannot be the same as any reserved word or keyword that has a predefined meaning in the assembly language.
    4. Case Sensitivity: The case-sensitivity of identifiers (whether myVariable and myvariable are different) depends on the assembler. For example, NASM is case-sensitive, but MASM is case-insensitive by default.

    1. Types of Identifiers

    There are various kinds of identifiers in assembly, each serving a different purpose:

    1.1. Data Identifiers

    These identifiers refer to variables, constants, or memory locations where data is stored. They are usually declared in the data segment and can be used to store values like integers, characters, or strings.

    • Variables: Named memory locations that hold data.

      message DB 'Hello, World!', 0  ; 'message' is a data identifier
      
    • Constants: Fixed values that do not change during execution. Constants can be defined using the EQU directive.

      MAX_VALUE EQU 100  ; 'MAX_VALUE' is a constant identifier
      
    • Arrays: A sequence of variables of the same type.

      arr DB 1, 2, 3, 4, 5  ; 'arr' is an array identifier
      

    1.2. Code Identifiers

    These identifiers are used to label instructions and create control flow mechanisms such as loops, function calls, and jumps. These identifiers are typically referred to as labels in assembly language.

    • Labels: Used to mark positions in the code so that they can be jumped to or called. Labels are useful for implementing loops, conditional branches, and function calls.
      start:                  ; 'start' is a label identifier
          MOV AX, 1
          JMP finish
      
      finish:                 ; 'finish' is another label identifier
          MOV AX, 0
      

    1.3. Register Identifiers

    In assembly language, registers are special locations in the CPU used to store temporary data. Registers have predefined names and are essential for operations. For example, AX, BX, CX, DX are all registers in x86 architecture.

    • Predefined Registers: These are fixed names for CPU registers.
      MOV AX, 10     ; 'AX' is a predefined register identifier
      

    1.4. Instruction Identifiers

    Instructions are the operations the CPU performs. These also serve as identifiers in assembly, but they are reserved words that trigger specific actions. For example, MOV, ADD, SUB, JMP, etc.

    • Instructions: These are typically opcodes (operation codes) that tell the CPU what to do.
      MOV AX, 5    ; 'MOV' is an instruction identifier
      ADD AX, 3    ; 'ADD' is another instruction identifier
      

    2. Rules for Naming Identifiers

    Each assembler may have specific rules for naming identifiers, but there are general guidelines that are applicable in most cases.

    2.1. Allowed Characters

    • Letters (A-Z, a-z): You can use alphabetic characters.
    • Digits (0-9): You can include numbers, but not as the first character.
    • Underscore (_): Typically allowed as part of an identifier.

    2.2. Starting Character

    • Identifiers must generally start with a letter or an underscore (_).
      • Valid: variable, _data, Label_1
      • Invalid: 1Variable, 123data (these start with numbers)

    2.3. Length

    • Most assemblers have limits on the length of identifiers, but generally, they support reasonably long names (e.g., 32 or 64 characters).

    2.4. Case Sensitivity

    • Some assemblers, like NASM, are case-sensitive, meaning that Variable and variable would be treated as different identifiers.
    • Others, like MASM, are case-insensitive by default, so Variable and variable would be treated as the same.

    2.5. No Reserved Words

    • Identifiers cannot be the same as any reserved word in the assembly language. Reserved words are keywords that have a predefined meaning and cannot be used for other purposes.

      Examples of Reserved Words:

      • MOV, ADD, SUB, JMP (Instructions)
      • DB, DW, EQU, SECTION (Directives)
      • AX, BX, CX, DX (Registers)

      If you try to name a variable MOV or AX, you would get an error because those are reserved by the assembler.

    3. Examples of Identifiers

    3.1. Data Identifiers

    .data
        msg DB 'Hello, World!', 0    ; 'msg' is an identifier for the string
        MAX_COUNT EQU 100            ; 'MAX_COUNT' is an identifier for the constant value
    

    Here:

    • msg is a data identifier referring to the string "Hello, World!".
    • MAX_COUNT is a constant identifier set to 100.

    3.2. Code Identifiers

    .text
    start:                          ; 'start' is a label identifier
        MOV AX, 1
        JMP next
    next:                           ; 'next' is another label identifier
        MOV AX, 0
    

    Here:

    • start and next are label identifiers. They refer to specific locations in the program to control program flow.

    3.3. Register Identifiers

        MOV AX, 10    ; 'AX' is a predefined register identifier
        MOV BX, AX    ; Copy value from AX to BX
    

    Here:

    • AX and BX are register identifiers used to reference CPU registers.

    4. Best Practices for Using Identifiers

    1. Use Meaningful Names: Although assembly language is low-level, using meaningful names for labels and data identifiers can make your code more understandable. For example, instead of naming a variable VAR1, use counter or input_data.

    2. Avoid Confusion with Reserved Words: Always check the assembler's reserved word list and ensure your identifiers don't conflict with them.

    3. Use Consistent Naming Conventions: If you're working with a team or planning to maintain the code long-term, follow a consistent naming convention for your identifiers. For example:

      • Prefix data variables with data_ (e.g., data_counter).
      • Prefix labels with label_ (e.g., label_start).
    4. Short, but Descriptive Labels: Labels in assembly are often short, but they should still give an idea of the program's flow. For example, use labels like loop_start, func_exit, etc., to indicate where loops or function exits happen.

    5. Avoid Overuse of Underscores: While underscores (_) are allowed, it’s better to use them sparingly and only when necessary (e.g., to separate words in an identifier, like counter_value).

    Conclusion

    Identifiers in assembly language are essential for creating readable and maintainable programs. They allow programmers to label data, registers, instructions, and other elements in a program. While the naming rules for identifiers may vary slightly between assemblers, they generally follow the same basic principles: use letters and digits, avoid reserved words, and choose meaningful names. By following best practices for naming identifiers, you can make your assembly code more understandable, even if it operates at a low level close to machine language.

    Previous topic 35
    Reserved Words
    Next topic 37
    Directives

    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,143
      Code examples0
      DifficultyIntermediate