what is a far pointer

Answer Posted / imran hassan bergi

Near pointers have a size of 2 bytes. They only store the
offset of the address the pointer is referencing. An
address consisting of only an offset has a range of 0 - 64K
bytes starting from the beginning of DGROUP. A near pointer
can be incremented and decremented using arithmetic
operators (+, -, ++, and --) through the entire address
range. Any attempt to increment a near pointer that has a
value of 64K (0xffff) will result in a value of 0. This is
referred to as wrapping the pointer. A corresponding result
can be expected when attempting to decrement a pointer that
contains an address of 0, except the result will be 64K
instead of 0. In addition to being incremented and
decremented, near pointers can be compared to one another
using relational operators ( <, >, ==, >= and <= ). Far
pointers have a size of 4 bytes. They store both the
segment and the offset of the address the pointer is
referencing. A far pointer has an address range of 0 - 1M
bytes. It is important to understand that an addressing
range of 1M does not remove the 640K barrier from the
program. It means that the pointer can address the upper
memory area (641 - 1M) which typically contains video
memory, ROM and anything else that may be loaded high. A
far pointer can be incremented and decremented using
arithmetic operators. When a far pointer is incremented or
decremented ONLY the offset of the pointer is actually
incremented or decremented. The segment is never
incremented by the arithmetic operators. This means that
although a far pointer can address up to 1Mb of memory, it
can only be incremented through 64Kb and the offset will
start at zero again without changing the value of the
segment. This is referred to as "wrapping" the pointer
(e.g. 0F3E:FFFF + 1 = 0F3E:0000). When a far pointer is
decremented from zero it will wrap the other way and become
64K. Far pointers are not unique. It is possible to have
two far memory addresses that have different segments
values and different offset values that address the same
memory location e.g. 0777:2222 has an absolute address of
07770 + 2222 = 09992 and 0999:0002 has an absolute address
of 09990 + 0002 = 09992. When relational operators are used
on far pointers only the offsets are compared. For example:
if we let a = 0777:2222 and let b = 0999:0002 then a == b
would return false because this is equivalent to 2222 ==
0002 which is in fact false. In other words relational
operators will only work on far pointers if the segment
values of the pointers being compared are the same. Huge
pointers have a size of 4 bytes. They store both the
segment and the offset of the address the pointer is
referencing. A huge pointer has an address range of 0 - 1M
bytes. A huge pointer can be incremented and decremented
using arithmetic operators. The only difference between a
far pointer and a huge pointer is that a huge pointer is
normalized by the compiler. A normalized pointer is one
that has as much of the address as possible in the segment,
meaning that the offset is never larger than 15. A huge
pointer is normalized only when pointer arithmetic is
performed on it. It is not normalized when an assignment is
made. You can cause it to be normalized without changing
the value by incrementing and then decrementing it. The
offset must be less than 16 because the segment can
represent any value greater than or equal to 16 (e.g.
Absolute address 0x17 in a normalized form would be
0001:0001. While a far pointer could address the absolute
address 0x17 with 0000:0017, this is not a valid huge
(normalized) pointer because the offset is greater than
0000F.). Huge pointers can also be incremented and
decremented using arithmetic operators, but since they are
normalized they will not wrap like far pointers. Huge
pointers can be reliably used with relational operators
because they are normalized. This works because
normalization of huge pointers insures that every huge
pointer is unique. It is important to understand that huge
pointers are never the default pointer, even in the huge
memory model.

Is This Answer Correct ?    27 Yes 5 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain what is a stream?

611


What happens if you free a pointer twice?

612


Explain union.

641


State two uses of pointers in C?

642


Explain void pointer?

594






Differentiate between ordinary variable and pointer in c.

621


what is associativity explain what is the precidence for * and & , * and ++ how the folloing declaration work 1) *&p; 2) *p++;

2008


What is a void pointer in c?

610


What is the use of putchar function?

653


How can a string be converted to a number?

521


What does the c preprocessor do?

625


What is use of integral promotions in c?

668


What is const and volatile in c?

568


I have written a pro*C program to fetch data from the cursor. where in i have used the concept of BULK FETCH.... each FETCH statement is taking lots of time to fetch specified number of rows at...

9662


What are volatile variables in c?

523