DWORD ptr instruction detailed parsing _c language

Source: Internet
Author: User

For this question, the assembly language uses the method to deal with.

(1) The size of the data to be processed is indicated by the register name.
For example:
In the following instruction, the register indicates that the instruction is a word operation:
MOV ax,1
MOV bx,ds:[0]
MOV Ds,ax
MOV Ds:[0],ax
Inc AX
Add ax,1000

In the following instruction, the register indicates that the instruction is byte-operated:
MOV al,1
MOV AL,BL
MOV al,ds:[0]
MOV Ds:[0],al
Inc AL
Add al,100

(2) In the absence of a register name, the length of the memory unit is indicated by the operator x PTR, and x can be word or byte in the assembly instruction.
For example:
In the following instruction, the memory unit that indicates the instruction access with Word ptr is a word cell:
mov word ptr ds:[0],1
Inc word PTR [BX]
Inc Word PTR ds:[0]
Add Word ptr [bx],2

In the following instruction, the memory unit that specifies the instruction access with byte PTR is a word unit:
mov byte ptr ds:[0],1
Inc byte PTR [BX]
Inc byte PTR ds:[0]
Add byte ptr [bx],2

In a memory unit access instruction without register participation, it is necessary to use Word prt or byte ptr to explicitly indicate the length of the memory unit to be accessed. Otherwise, the CPU has no way of knowing which cell to access or a byte unit.

If we use debug to view memory, the results are as follows:
2000:1000 FF FF FF FF FF ...

Then instructions:
MOV ax,2000h
MOV Ds,ax
mov byte ptr [1000h],1
will make the contents in memory into:
2000:1000 FF FF FF FF ...

and instructions:
MOV ax,2000h
MOV Ds,ax
mov word ptr [1000h],1
will make the contents in memory into:
2000:1000 FF FF FF FF ...

This is because the mov byte ptr [1000h],1 accesses the ds:1000h byte cell, modifies the contents of the Ds:1000h cell, and the Mov word ptr [1000h],1 accesses a word cell with a ds:1000h address, which modifies the DS : 1000H and ds:1001h contents of two units.

PTR is used to indicate the type or size of an operand, usually used in a jump/tone program or addressing. When addressing is used to indicate byte, Word, or DWORD, the jump is far or near.

(3) Other methods
Some directives default to whether a word cell or byte unit is accessed, such as: Push [1000H] does not have to indicate whether to access a word cell or a byte unit, because the push instruction only carries out word operations.

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.