near pointer, segmentation - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

near pointer, segmentation

c_and_mec_and_me Posts: 3Member
hi,
i am programming in Turbo C 3 now-a-days, with Windows XP as my OS. and i hv some questions about it.

1. does TC 3 tht i am using produces executables actually for DOS tht are
16 bit apps.?

2. for 32 bit FAR pointers i know tht the real address is calculated as:
seg. no. * 16(HEX) + offset. it converts the 32 bit virtual address into
a 20 bits real address.
how is the 16 bit near pointer virtual address converted into a 20 bit
real address?

3. who converts the virtual address into a real address in the computer
when a C program is compiled?

4. wht is meant by overlapping segments? the virtual addresses r from
0000:0000 to FFFF:FFFF. so we can define 16*16*16*16 segments, each
starting from an address divisible by 16. if i am right then please
let me know, how is it beneficial in actual programming? otherwise
otherwise please correct me.

thanks.

Comments

  • zibadianzibadian Posts: 6,349Member
    : hi,
    : i am programming in Turbo C 3 now-a-days, with Windows XP as my OS.
    : and i hv some questions about it.
    :
    : 1. does TC 3 tht i am using produces executables actually for DOS
    : tht are
    : 16 bit apps.?
    :
    : 2. for 32 bit FAR pointers i know tht the real address is calculated
    : as:
    : seg. no. * 16(HEX) + offset. it converts the 32 bit virtual
    : address into
    : a 20 bits real address.
    : how is the 16 bit near pointer virtual address converted into a
    : 20 bit
    : real address?
    :
    : 3. who converts the virtual address into a real address in the
    : computer
    : when a C program is compiled?
    :
    : 4. wht is meant by overlapping segments? the virtual addresses r
    : from
    : 0000:0000 to FFFF:FFFF. so we can define 16*16*16*16 segments,
    : each
    : starting from an address divisible by 16. if i am right then
    : please
    : let me know, how is it beneficial in actual programming?
    : otherwise
    : otherwise please correct me.
    :
    : thanks.
    :
    :
    1: Yes.

    2: The program "knows" in which segment the code is located. For all near pointers it will simply use that segment. For data it will use the segment containing the pointer location.

    3: OS

    4: Don't know.
  • stoberstober Posts: 9,765Member ✭✭✭
    You need to study assembly language in order to answer most of your questions. register ds or es contains the segment address and one of the other registers contains the offset into that segment where the data is located. register cs always contains the segment of the code that is being executed and register ip contains the offset within the code segment (cs) of the current instruction.

    Segment offsets are always know by the compiler at compile time, but actual segment values are not known until the os loads the program into memory. The os program loader is responsible for resolving all segment addresses and modifying the program accordingly.

    Near pointers are exactly like far pointers except the ds register is assumed to contain the correct segment value of the data. As you can see from the example below near pointers in assembly language can be either with or without the segment register. Far pointers always use the segment register because the value in that register can change.
    [code]
    Near pointer: mov [bx],0
    or
    mov [ds:bx],0

    Far pointer: mov [ds:bx],0
    [/code]
    =============================================
    never lie -- the government doesn't like the competition. (Author unknown)
  • cactus1cactus1 Posts: 41Member
    : 4. wht is meant by overlapping segments? the virtual addresses r
    : from
    : 0000:0000 to FFFF:FFFF. so we can define 16*16*16*16 segments,
    : each
    : starting from an address divisible by 16. if i am right then
    : please
    : let me know, how is it beneficial in actual programming?
    : otherwise
    : otherwise please correct me.
    :
    : thanks.
    :
    :
    Overlapping segments is the small area where two consecutive segments share 16 bytes of memory.
  • c_and_mec_and_me Posts: 3Member
    thanks a lot for ur replies. i understood the near and far pointer conversions.
    the points are:
    1. when we use near pointer such as xxxx:yyyy, where the xxxx part is not mentioned the xxxx part is taken from some register int the CPU and the real address is calculated as:
    xxxx*16 + yyyy.
    same thing happens in far pointers but the xxxx part has to be given by us.
    am i right?

    2. suppose there is a virtual address xxxx:yyyy.
    the 1 MB addressable memory in DOS is divided into sixtenn segs. now we can get 16 segments of the memory by using just one hex digit. say the first dgit. what is the use of the other three digits?

    3. plz. suggest me a good assembly language book, for understanding all these things(preferebly with reference to DOS).

    thanks again.
  • c_and_mec_and_me Posts: 3Member
    please answer, i m in real need.
    thanks.
Sign In or Register to comment.