Daily Lesson (13/75) memory variable definition

Source: Internet
Author: User
The identifier and expression are Program Two concepts frequently used in design: when programming in advanced languages, if the program needs to process a change volume, generally, you need to define a symbolic name with a certain data type for the variable. This is also used in assembly languages, the difference is the description and reference method.

1. identifier
In assembly languages, labels, memory variable names, subroutine names, and macro names are all identifiers. Generally, they can contain up to 31 letters, numbers, and specified special characters (? And cannot start with a number. In general, the assembly language does not distinguish between uppercase and lowercase letters in the identifier.

Like the variable names in advanced languages, the names of identifiers are generally required to be meaningful, which improves the readability of the program and facilitates understanding of the program. However, identifiers cannot be reserved words in assembly languages, reserved Words in the assembly language are mainly: Command mnemonic, pseudo-command definition, register name, and some strings with special meanings.

2. simple definition of memory Variables
During programming, some memory units are often defined according to program needs. In advanced languages, you need to give a symbol name to the storage unit, and then reference the symbol name to access the corresponding storage unit. However, in assembly language programs, you need to be flexible, it can give the storage unit a symbolic name or not. When a storage unit is given a symbolic name, the corresponding storage unit can be accessed through this symbolic name. If a storage unit is not given a symbolic name, you can access it through the offset of the storage unit.

In assembly languages, common data types include byte, word, and double-word.

1. General Form of memory variable definition
Statements defining data variables are commonly used pseudo-command statements in programs. The format is as follows:

[Variable name] delimiter expression 1 [, expression 2]; Comment

(1) The variable name must be a valid identifier that can be written or not written (it can only be accessed through the memory unit offset when not written)
(2) Data delimiters are used to determine the data types of memory units. Common delimiters include dB dw dd.
(3) The expression is the initial value expression when defining a memory unit. A definition statement can have multiple initial value expressions separated by commas, if a storage unit does not have an initial value, a question mark must be used? To indicate
(4) It is optional to write comments after the Definition Statement.

When defining a variable, although the variable name is optional, it must be written. Otherwise, addressing is inconvenient (it is not as convenient to use an offset)

2-BYTE Variable
The definition character of the BYTE variable is dB/byte, and each byte occupies only one byte unit. Here, byte is the data type specifier of masm6.0 and later versions.
For example:
Counter dB 6
DB 'A', 'D', 0dh, '$'
Table dB 1, 3, 5, 7, 9, 11

The memory units generated after the preceding Definition Statement is compiled are as follows:

...

06

41

44

0d

24

01

03

05

07

09

0b

...

Counter points to the first lattice 06, And the 'A' ASCII code is 41, so the second memory unit is 41, and the table points to the 01 lattice.
The second row of the definition statement does not provide a variable name. when accessing these storage units, you can use counter to offset backward or use table to offset forward. This is different from the advanced language. The advanced language uses an identifier to describe the variable and must use this variable name to access a storage unit.

The database can also define strings. When defining strings, you must enclose the characters in single or double quotation marks. The characters in the quotation marks are placed in byte units at a time.
For example:
Msg1 DB "I am a student ."
Memory units generated after assembly:

... 'I '' 'A' 'M' '' 'A' '' 's ' 'T' 'U' 'D' 'E' 'n' 'T' ...

(In fact, all the above grids should contain ASCII code, which is more intuitive)
3. Word Variables
The definition character of the variable is DW/Word, and each word occupies two consecutive memories.
For example:
Word1 DW 89 h, 1989 H,-1
DW 0 abcdh ,?, 0
The memory allocation is as follows:

89 00 09 89 FF FF CD AB -- -- 00 00 ...

4. Double-character Variables
The dual-word variables are defined by DD/DWORD. Each dual-word variable occupies four memories.
For example:
Dw1 dd 12345678 H ,?
Dw2 dd 0abcd1243h

78 56 34 12 -- -- -- -- 43 12 CD AB

5. Multi-character Variables
Six-character variable: DF
Eight-character variable: DQ
Cross variable: dt

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.