[comp.sys.ibm.pc] ASM segment questions

dennis@rlgvax.UUCP (Dennis.Bednar) (11/13/87)

In article <585@ihnet.ATT.COM>, tjr@ihnet.ATT.COM (Tom Roberts) writes:
> 
> compiler to utilize that hardware. In the most common memory model
> (SMALL), the above macros will not let you reference outside of your
> DGROUP "segment" (DGROUP is a segment to the HW, but a "group" to the
> linker - thanks a bunch Microsoft (:-();

Tom and the net:

Its unclear to me exactly how the segment assembler directive
is used by LINK.  I even read one of the MS_DOS reference books,
but the discussion was very cloudy (not even the technical
editors understand this very well, it seems :-} ).  I have
my own vague notion that you use it to ensure that the segments
declared in separate .asm files will be forced to reside at
different non-overlapping offsets within in the same
physical 64K segment (thats what you want for data, since
it avoids constantly reloading the DS register if data were
otherwise scattered over lots of different 64k physical segments, right?)

So my question is this, given the following ASM statement:
label	segment	para public 'CODE'

how does the linker use label (if at all) and CODE (if at all)?

Please post replies to the net, as I am sure others would be interested.

-- 
FullName:	Dennis Bednar
UUCP:		{uunet|sundc}!rlgvax!dennis
USMail:		CCI; 11490 Commerce Park Dr.; Reston VA 22091
Telephone:	+1 703 648 3300

gkb@necntc.NEC.COM (Greg Busby) (11/13/87)

In article <700@rlgvax.UUCP> dennis@rlgvax.UUCP (Dennis.Bednar) writes:
>So my question is this, given the following ASM statement:
>
>	label	segment	para public 'CODE'
>
>how does the linker use label (if at all) and CODE (if at all)?
>Please post replies to the net, as I am sure others would be interested.
>FullName:	Dennis Bednar

label	is the name of hte segment.  this means that any other segment
	declarations with the name 'label' will be part of the same
	segment as far as the linker is concerned.

segment	is the masm command that says this is a segment :-).

para	is the linkage attribute, which says the segment must start on
	an even paragraph (multiple of 10H) when loaded.  this is
	retained by the linker.

public	is the combination type, which tells the linker how to allocate
	memory for this segment.  public means that the information in
	this segment will be combined such that the segment size is
	equal to the total size of all segments named 'label' in class
	'CODE' in all modules linked, and that the info will be placed
	in memory n the order it is encountered n the different modules.
	this is the most common combination type.

CODE	is the class name.  you can have segments of the same name 
	(eg. label) but in different classes, and they are NOT in the
	same hardware segment (although in some memory models they will
	happen to be) unless they are GROUPed together. (Isn't this
	fun?).  class information is retained in the final .exe file, 
	and can be used by some programs to locate addresses for 
	producing rommable code, etc.  for example, in a C program the 
	_DATA segment and some others (ie. _CVTSEG, _SCNSEG in turboc)
	will all be (or should all be) in the 'DATA' class.  _TEXT will
	be in the 'CODE' class.  _DATA, _BSS, _BSSEND, _STACK will all
	be in the group DGROUP, which is the hardware segment DS (again,
	small model).

There are lots of tricks which can be employed in setting up segments,
but if you don't know them you probably don't need them.  the simple
segment definition that you gave at the top iwll work just fine for most
assembly programs, with one code and one data segment.  if you are using
more than 64k code and 64k data, use C and don't worry about it :-).

GKB

-- 
* I'm not sure what upsets me more -- that people are so unwilling to
* accept responsibility for their own actions, or that they are so
* willing to regulate everyone else's -- Anon.