far pointer

(1) What is far pointer?
Far pointer is 32 bit pointer .It can hold the address of variable in the data segment as well as outside of the data segment.

This type modifier is usually used when compiling in the tiny, small or compact memory model to force the pointer to be far. It stores both offset address as well as segment number of any variable But when you will increment far address then only offset address will increase (same way as in near pointer).Its segment number never will change. In dos.h header file there two function that can find offset address and segment address which take the argument far pointer and return unsigned int.
unsigned int FP_OFF(void far *)
unsigned int FP_SEG(void far *)
void main()
unsigned int i,offset_addr,seg_addr,;
char far *ptr=(char far *) 5555 FF99;
for (i=0;i<300 data-blogger-escaped-br="" data-blogger-escaped-i="">{
printf(“\n seg_addr %x offset_addr %x ”,seg_addr,offset_addr);
Output :

You can see its segment address is not changing. In relational operation whole far address is compared.

No comments: