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.
myVariable and myvariable are different) depends on the assembler. For example, NASM is case-sensitive, but MASM is case-insensitive by default.There are various kinds of identifiers in assembly, each serving a different purpose:
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
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.
start: ; 'start' is a label identifier
MOV AX, 1
JMP finish
finish: ; 'finish' is another label identifier
MOV AX, 0
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.
MOV AX, 10 ; 'AX' is a predefined register identifier
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.
MOV AX, 5 ; 'MOV' is an instruction identifier
ADD AX, 3 ; 'ADD' is another instruction identifier
Each assembler may have specific rules for naming identifiers, but there are general guidelines that are applicable in most cases.
_).
variable, _data, Label_11Variable, 123data (these start with numbers)Variable and variable would be treated as different identifiers.Variable and variable would be treated as the same.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.
.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..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. 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.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.
Avoid Confusion with Reserved Words: Always check the assembler's reserved word list and ensure your identifiers don't conflict with them.
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:
data_ (e.g., data_counter).label_ (e.g., label_start).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.
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).
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.
Open this section to load past papers