Daily Course (17/75) Labels and attributes

Source: Internet
Author: User

Level 1
A label is a special identifier, representingCodeSegment, which is mainly used to jump to the target position of the command. The description is as follows:
Number: Assembly Statement; Comment
The label must be a valid identifier followed by a colon. the colon and the Assembly statement are separated by tabs or spaces.

Attributes of two memory variables and labels
A variable is a symbolic address. Its value corresponds to the values of several storage units after the address based on the data type it represents.
A label is also a symbolic address. The corresponding storage unit stores instruction code. Although they are different in nature, they all represent a memory address, therefore, they all have the attributes of storage units.

The following describes the attributes and operators of memory variables and labels.

1-segment attribute Operator
The segment attribute operator (SEG) returns the segment address of the identifier. Generally, only the segment address of the memory variable is used, and the segment address of the label is rarely used.
The usage is as follows:
Scope DW?
Name dB 10 DUP (10)
MoV ax, SEG Scope
MoV BX, SEG name
Now the value of ax is equal to the value of BX, because name and scope are defined in the same segment.

2 offset attribute Operators
Offset returns the number of bytes from the base address of the specified identifier segment. Generally,ProgramThe member only pays attention to the offset of the memory variable, but seldom pays attention to the offset of the label.
For example:
First dd 12345678 H, 0
Scope DW ?, 12 h
Name dB 10 DUP (10)
MoV ax, offset Scope
MoV BX, offset name
If first is the first defined memory variable, at this time, ax is 8, then two words (4 bytes), and BX is 12.

3. Type attribute Operators
The type operator can return the number of bytes occupied by the variable or the distance type of the label.

4. Length attribute Operators
The Length attribute operator (length) is a memory variable operator that returns the number of duplicates in the repeated operator DUP.

5 Capacity attribute Operators
The size operator is length * type.

6. Mandatory attribute Operators
In a program, you sometimes need to access the same storage unit with different attributes, or when you need to display specified attributes for some uncertain storage attributes, You need to force the attribute operator PTR.
For example, there is a command: mov [BX], 1 H is an indirect addressing method, which stores 1 h in the Register unit referred to in BX, in the actual transfer operation, is the "1 H" extended to 8 bits for byte transmission or 16 bits for word transfer? In this way, the instruction has the ambiguity, because the [BX] point to a storage unit that can be the first address of a byte or word, the code containing this instruction may fail during assembly.

To enable explicit attributes of unit operations in commands, you can use the force attribute operator PTR. Format:
Data Type PTR address expression

To clarify the attributes of the storage unit in the command, you can rewrite the command mov [BX], 1 h
MoV byte PTR [BX], 1 h
MoV word PTR [BX], 1 h

After you use the PTR operator in the instruction to specify a memory address and the data element type after it is specified, the command takes the type specified by PTR as the standard. This force attribute is only valid in the instruction, does not affect the definition attributes of the original memory unit.

For example:
W1 DW 1234 H, 5678 H
B1 DB 2
DB 5
D1 dd 23456789 H
MoV ax, word PTR B1; after execution, Ax = 0502 H
MoV BH, byte PTR W1; bH = 34 h after execution
MoV CH, byte PTR W1 + 1; CH = 12 h after execution
MoV word PTR D1, 12 h; D1 = 23456712 h after execution

7. Alias operators for storage units

You can use the PTR force attribute operator to access a memory address and several memory units following it in the form of a specific data type. However, every time you use the PTR force type operator, you can declare an alias of another type for a memory variable. Then you can use the data type of the alias to access the memory variable.
Format:
This data type

For example:
Wbuffer equ this word; Word type variable wbuffer
Buffer dB 20 DUP (?) ; Byte type Variable Buffer

At this time, we can see that the memory variable declared by this does not open up the memory space, but indicates that the memory variable references this memory address with the specified data type, use the following data definition statement to open up the actual memory space

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.