The pseudo-instruction of assembly language programming label and this

Source: Internet
Author: User

First talk about some of your own understanding: from a high-level language of the basic say

In high-level languages, we sometimes initialize the property settings for a segment of storage space, such as the initial access to the storage space is int, each time the IP = Ip+4, and now want to access in bytes (char), then you need to force type conversion, but this conversion is only useful for a single operation.

int A[10]

Char *p = (char*) A;

If you need time later, you need to convert again.

In assembly language programming, set up the relevant pseudo-directives, to achieve a similar type of conversion, in fact, a piece of storage space or a code snippet of the definition of the alias (alias, for high-level language C + + familiarity, should know the reference (&) it).

For the storage space, we understand the variable, the property of this variable contains three parts: segment base, paragraph offset, type description (byte-byte, word-Word, dword-double word, etc.);

For the access to execute instructions, denoted by the label, the label represents an execution instruction in the assembly code address identifier, usually is a symbol + a colon, this symbol we call the label, the label also contains three attributes: segment base, offset within the paragraph, Access description (near Access-module interior + Far remote access-between modules).

A label is a symbol name definition statement. The statement defines a specified symbol name with the same segment address and offset as the corresponding property immediately following the storage cell, but the type of the symbol is newly specified. The general format of the label statement is as follows:

symbol name LABEL type

Among them: Commonly used types are BYTE,WORD,DWORD, near and far, and so on.

To illustrate:

 
..... Wbuffer LABEL WORD; Wbuffer and buffer have the same segment address and offset, but their data types are different. 
BUFFER DB-DUP (0) ... 
NEXT1 LABEL far; NEXT1 and next have the same segment address and offset, NEXT1 is the "far" label, and Next is the "near" label. 
Next:mov AX, BX

On top, the label NEXT1 and next can be used in different situations. When transferring within the same module, the label next is used, and the "far" label NEXT1 is required when transferring between different modules.

When it comes to labels, you have to mention the This operator, which is very similar to its function.

We know that in a program, if you need to access a storage unit with another data type, you can use the force attribute operator ptr to implement it. However, if the storage unit is accessed frequently in a program with some other data type, the mandatory attribute operator PTR must be added to each access. While this works, it can be cumbersome to write programs.

To overcome these inconveniences, assembly language provides another operator this, which takes another alias for the same storage unit, which can have its own data properties, but its segment address and offset are constant.

The general format of the operator this is:

This data type

Where: Commonly used data types are: BYTE, WORD, DWORD, near and far, and so on.
For example:

Wbuffer EQU this WORD; Equ is an equivalent symbol definition statement 

The schematic is shown below:

In this case, Wbuffer is an alias for the buffer, and the two variable names actually point to the same memory address. However, it is important to note that the two types may be different. In the example above, Wbuffer is a word type, and buffer is a byte type. Therefore, in a program, with different variable names, there are different properties:
If you use Wbuffer, it will be accessed according to Word, and if you use buffer, it will be accessed by byte.

Looking back:

mov ax,word ptr BUFFER and mov AX, wbuffer the two are equivalent. The former uses a forced property conversion to convert a byte-type buffer to a word type, which is an alias for the type of word that is set with this.

The same alias reference, but because the property settings are different, the way to access is also different

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.