What is the difference between “PTR” and “NEAR PTR

2019-08-26 22:05发布

I was looking up examples containing “NEAR PTR”, but they were easily replaceable with “PTR”. Is there any advantage for using “NEAR PTR”?

1条回答
时光不老,我们不散
2楼-- · 2019-08-26 22:35

NEAR is a legacy from 16-bit past. Assuming your code is 32-bit or 64-bit, they are the same.

This is about memory segments (Wikipedia link to x86 32-bit and to 64-bit).

In LABEL statement both PTR and NEAR PTR just store a 32/64 bit memory address without segment.

If compile next code under 64-bit MASM:

_DATA SEGMENT
    justPtr LABEL PTR db
    nearPtr LABEL NEAR PTR db

    justPtrSize dd SIZEOF justPtr
    nearPtrSize dd SIZEOF nearPtr
_DATA ENDS

and check under Visual Studio debugger the sizes:

?justPtrSize
8
?nearPtrSize
8

Indeed PTR occupies 8-byte (64 bit), same way as NEAR PTR does.

查看更多
登录 后发表回答