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

≯℡__Kan透↙ 提交于 2019-12-11 18:29:03

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/55843936/what-is-the-difference-between-ptr-and-near-ptr

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!