When programming MASM in 32 bit flat memory model, is there any difference between the following data types:

near ptr
far ptr


If there is no difference, is any of them to prefer when writing the code anyway, and in that case why?

Posted on 2002-11-21 07:30:22 by dELTA
They are all the same, because the memory model "flat" has everything in the same really big (4Gb) chunk of addressable memory.

Which is prefereable:

Because its a whole 5 characters less than "near ptr", and 4 less than "far ptr".
Its also less confusing to people who may think its 16 bit code.

Posted on 2002-11-21 08:46:29 by Mirno
It was used to size the data width for an operation, byte ptr, word ptr, etc. without doing a lot of definations or declarations.

In this case, it sizes the offset amount for the IP ( instruction pointer ) for the next instruction.

Regards, P1
Posted on 2002-11-21 13:04:23 by Pone
Hmm, could someone please explain how this offset adjustment works? The pointers are just data, so when is the EIP adjusted? In every instruction that reference this data? Sounds very strange to me?

Posted on 2002-11-21 13:35:39 by dELTA

In relation to your original question, in 32 bit FLAT memory model all pointers are NEAR which means within one segment. It just happens to be that the segment size is 4 gig.

Specifying PTR in masm is for avoiding ambiguity in some instructions,

mov BYTE PTR [esi], 0 ; move memory immediate

mov [esi], 0 ; error data size unknown

EIP is the instruction pointer and is generally well left alone. You can change the instruction pointer with JMP CALL and RETN (RET) and the conditional jumps JZ JE etc ...

EIP is controlled by the processor so that the instruction sequence is processed in order. You change the order with the instructions above.


Posted on 2002-11-21 17:52:10 by hutch--
Thanks for your reply Hutch (and thanks for MASM32!)!

Even though I'm quite the noob, I do know what EIP is, and how it works (pone's reply was a bit confusing to me, but I think he just misunderstood my question, thinking it was about "byte/word/dword ptr" instead of "near/far ptr"). I also already know that segments are 4 GB in flat model.

It is good to have it confirmed by you that all pointers are of "near" type in flat model though. What made me ask this question in the first place was the fact that MASM accepts all three pointer types in my flat mode program ("ptr", "near ptr" and "far ptr").

So, to summarize the question:

Will there be no difference whatsoever if I write "ptr", "near ptr" or "far ptr" for the pointer variables in my flat mode program? And, is there any "common practise" about which one you usually write anyway, e.g. "ptr"?

Thanks a lot!
Posted on 2002-11-22 07:11:22 by dELTA

'near ptr' implied only the IP would receive a new value/offset to the new instruction.
'far ptr' implied that the CS:IP would both receive a new value(s)/offset(s) to the new instruction.

I hope this clarifies my previous answer.

Regards, P1
Posted on 2002-11-25 09:14:01 by Pone
Yes, but in a 32-bit flat model program, does this mean that "far ptr" is 48-bit (16 bit segment + 32 bit offset), or is it still just a 32 bit offset? The whole reason I got confused in the first place is that MASM will allow me to write "far ptr" and "near ptr" in a 32-bit flat model program at all?!?

And what does a single "ptr" default to? Offset only (near ptr), or segment : offset (far ptr)?
Posted on 2002-11-25 12:22:44 by dELTA