Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- CA-Clipper/ExoSpace 1.0g - <b>no arithmetic on segment addresses</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 No Arithmetic on Segment Addresses
------------------------------------------------------------------------------

     Because a protected-mode selector points to a descriptor, and not
     directly to a physical segment, the arithmetic that you can do with the
     segment portion of a pointer in real-mode applications does not work in
     protected mode.  Segment arithmetic occurs most often in pointer
     manipulation.

     In real mode, adding 1 to a segment value describes a physical location
     16 bytes (or one paragraph) higher in memory.  In protected mode, adding
     1 to a selector results in an error.

     You can freely do arithmetic on the offset part of a pointer.  For
     example, you can subtract the offset of a starting pointer from the
     offset of an ending pointer, as long as the selectors are the same in
     both pointers.  Two pointers that have the same selector refer to the
     same segment in memory.

     Normal C pointer arithmetic works in protected mode.  For example, the
     following code is valid:

     int a[30];
     int *p;
     p = &a[0];
     p += 3;
                    /* == &a[3] */

     You can also split pointers.  For example, to copy from the middle of a
     table to the same offset in another table, you can change just the
     selector address.

     It is relatively cumbersome to look inside pointers in C, so segment
     arithmetic problems occur most often in assembly language.  Memory
     managers are the most likely kind of software to violate this
     restriction.  Segment arithmetic also shows up in library functions like
     spawn or system that call the DOS function 4Bh.  Uninitialized far
     pointers may cause a protection exception, as well.

     The 80286 instruction set does not have any 32-bit instructions suitable
     for doing pointer arithmetic.  Therefore, each compiler generates its
     own 32-bit pointer arithmetic from the processor's 16-bit arithmetic
     instructions.

     If your program does segment arithmetic to overcome the 64 KB segment
     size limit of the 80x86 machines, use your compiler's far or huge
     pointers, or use the CA-Clipper/ExoSpace huge allocation functions.  If
     your program converts integers or long integers to pointers, make sure
     that the resulting values are valid protected-mode selector values, and
     that they are the addresses that you intended.  (See Absolute Addresses
     in this chapter.)


Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson