Variables and Constants in Assembly Language

Variables in Assembly Language:

Variables are symbols used in assembly language program statements in order to represent the variable data and address. While running a program, a value has to be attached to each variable in the program. The advantage of using variables is that the value of the variable can be dynamically varied while running the program.

Rules for variable names:

1. The variable name can have any of the following characters. A to Z, a to z, 0 to 9, @, _(underscore).

2. The first character in the variable name should be an alphabet ( A to Z or a to z) or an underscore.

3. The length of a variable name depends on the assembler and normally the maximum length of a variable name is 32 characters.

4. Variable names are case insensitive. Therefore, the assembler does not distinguish between the upper and lower case letters/alphabets.

Constants in Assembly Language:

The decimal, binary, or hexadecimal numbers used to represent the data or address in assembly language program statements are called constants or numerical constants. When constants are used to represent the address/data then their values are fixed and cannot be changed while running a program. The binary, hexadecimal, and decimal constants can be differentiated by placing a specific alphabet at the end of the constant.

Examples of valid constants:
1011 – Decimal (BCD) constant
1060 D – Decimal constant
1101B – Binary constant
92ACH – Hexadecimal constant
0E2H – Hexadecimal constant

Examples of invalid constants:
1131B – The character 3 should not be used in binary constant.
0E2 – The character H at the end of the hexadecimal number is missing.
C42A H – Zero is not inserted at the beginning of a hexadecimal number and so it is treated as a variable.
1A65 D – The character A should not be used in decimal constants.