The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: P3t3 on November 11, 2010, 11:38:02 PM

Title: Executable format under Windows
Post by: P3t3 on November 11, 2010, 11:38:02 PM
Hi,

New to 32-bit assembly programming. But did alot of 16-bit assembly in the days of DOS.
So getting into this whole 32-bit thing.

A simple question, which executable type do I build under Windows Vista/7 ?
Coff, PE?

And can someone simply explain them please.

Cheers
Title: Re: Executable format under Windows
Post by: jj2007 on November 12, 2010, 01:57:41 AM
Welcome to the Forum :thumbu

You would typically use these commandlines:

\Masm32\bin\ml.exe /nologo /c /coff MyFile.asm

If you have resources:
  \masm32\bin\rc rsrc.rc

  With polink:
  \masm32\bin\polink.exe /SUBSYSTEM:WINDOWS MyFile.obj rsrc.res

  With link:
  \masm32\bin\cvtres /machine:ix86 rsrc.res
  \masm32\bin\link.exe /SUBSYSTEM:WINDOWS MyFile.obj rsrc.obj

If you do not have resources (assuming console app - could be WINDOWS, too):
  \masm32\bin\link.exe /SUBSYSTEM:CONSOLE MyFile.obj

COFF refers to the format produced by the assembler, i.e. *.obj
PE is the final format produced by the linker, i.e. *.exe

More at Microsoft (http://www.microsoft.com/whdc/system/platform/firmware/pecoff.mspx) or google for executable format coff PE.

Here are some tips, tricks and traps. (http://www.webalice.it/jj2006/Masm32_Tips_Tricks_and_Traps.htm)

Hope this helps,
Jochen

EDIT: Corrected the linker command lines - polink accepts *.res, link doesn't.
Title: Re: Executable format under Windows
Post by: dedndave on November 12, 2010, 02:00:55 AM
if you use the forum search tool, Hutch posted a PDF for version 8 of the PE spec
i had posted it long ago, but Hutch's file was a bit smaller

welcome to the forum   :U
Title: Re: Executable format under Windows
Post by: hutch-- on November 12, 2010, 06:20:26 AM
P3t3,

The basic are this, Win32 uses a "Portable Executable" format specific to Microsoft that has a DOS "MZ" header, usually referred to as the DOS stub followed by a PE (Portable Executable) header, a code or TEXT section that contains the executable code, a DATA section that contains initialised data and a resource section that contains things like bitmaps, icons, dialogs etc ....

The PE spec use a FLAT memory model that is a linear 32 bit address space and memory is addressed as 32 bit linear, there are no segment/offset based addressing in 32 bit PE. The base 32 bit PE works on every Windows version from Win95 OEM up to the 32 bit section of Win7 64 bit OS versions. DOS 16 bit real mode interrupts do not work in FLAT memory model 32 bit code (A few did in early win95) and you perform your OS based code using the Windows API functions instead.

The document to get from Microsoft is called PECOFF.DOCX which contains the 32 bit PE specifications.
Title: Re: Executable format under Windows
Post by: P3t3 on November 12, 2010, 12:40:49 PM
Thanks heaps guys. That has helped.

I forgot to mention in my first post, how much I love assembly language.
I haven't code in x86 assembly since the early 90s.

Developing in high level languages over the years, just doesn't fill that void.
My passion is and always will be assembly language.
Title: Re: Executable format under Windows
Post by: Vortex on November 12, 2010, 07:27:00 PM
Hi P3t3,

Welcome to the forum.