views:

128

answers:

1

I am new to MASM. So the questions may be quite basic.

When I am using the MASM assembler, there's an output file called "Link Map". Its content is composed of the starting offset and length of various segments, such as Data segment, Code segment and Stack segment. I am wondering that, where are these information describing? Are they talking about how various segments are located within an EXE file or, how segments are located within memory after the EXE file being loaded into memory by a program loader?

BTW: What does the "Assume" directive do? My understanding is that it tell the assembler to emit some information into the exe file header so the program loader could use it to set DS, CS, SS, ES register accordingly. Am I right on this?

Thanks in advance.

+1  A: 

Linker map

this is not MASM specific. It is part of the linker. I.e.

ml /Fm foo.asm

is the same as

ml foo.asm /link /map

or

ml /c foo.asm
link foo.obj /map

cl.exe has this option too (/Fm) which does the same thing.

It is a list of the sections that are placed in the EXE or DLL image, in the order they appear. E.g. code, data, resources, import table, export table, etc.

The offset is relative to the start of the image section. A number of object sections may be combined into an image section by the linker.

E.g.

 0002:00001514 00000014H .idata$2                DATA
 0002:00001528 00000014H .idata$3                DATA
 0002:0000153c 000000f8H .idata$4                DATA
 0002:00001634 00000464H .idata$6                DATA

The above are object sections (they come from .obj files) since they contain a suffix starting with $. The linker will merge them into one section .idata in the final image module (in lexicographic order of the suffix). The offset is relative to the start of where the linker will allocate the import address table (.idata section).

Assume

Provides compile-time checks, to prevent accidental misuse of registers. It doesn't generate any code. See

Alex
Thanks, Alex. So the offset in a link map means the offset relative to the start of an EXE file on disk? Nothing to do with the in-memory location.
smwikipedia
No, it is the offset relative to the start of the image section. I suppose I should explain the difference between object and image sections.
Alex
So, it is an offset in file, not in memory?
smwikipedia