Beginner C/C++

Moderators: None (Apply to moderate this forum)
Number of threads: 5428
Number of posts: 16943

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
near pointer, segmentation Posted by c_and_me on 2 Jun 2007 at 10:58 PM
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.

Report
Re: near pointer, segmentation Posted by zibadian on 2 Jun 2007 at 11:31 PM
: 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.
Report
Re: near pointer, segmentation Posted by stober on 3 Jun 2007 at 4:28 AM
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.
Near pointer:  mov  [bx],0
         or
               mov  [ds:bx],0

Far pointer:   mov  [ds:bx],0

=============================================
never lie -- the government doesn't like the competition. (Author unknown)
Report
Re: near pointer, segmentation Posted by cactus1 on 3 Jun 2007 at 6:15 AM
: 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.
Report
Re: near pointer, segmentation Posted by c_and_me on 3 Jun 2007 at 8:31 AM
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.
Report
Re: near pointer, segmentation Posted by c_and_me on 3 Jun 2007 at 9:17 PM
please answer, i m in real need.
thanks.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.