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 PortalCOMP3137Identifiers
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 36 of 73
    Topic Study Note Illustration
    36

    Identifiers

    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...

    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 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