The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: OceanJeff32 on October 05, 2005, 01:29:25 AM

Title: .exe file question
Post by: OceanJeff32 on October 05, 2005, 01:29:25 AM
Ok, so I'm reading a book about MASM 6.0 and 6.1, and it's talking about the differences between .exe and .com files.

My question is this:

When the .exe program is created can you reference the first data byte/word/dword in the data section by utilizing the DS register?  What are the other segment registers good for? anything?

According to this book, the DS and ES point to the very beginning of memory allocated for this program, before the program segment prefix (PSP)? AND the CS points to 100h, which is the beginning of the code segment.  AND the SS points to some further stack segment later in memory.

Is all of this still true? And is it still viable to use these registers for operations?  I was just curious, because I am also looking back into 16-bit DOS programming, and am finding that I will have to make significant use of them.  So converting code from 16-bit DOS to 32-bit Windows or DOS (emulated by Windows) is simpler because these registers are not necessary to keep track of?

I can go into the command line, and create a .com file with debug that executes (properly  :green), and is only 31 bytes long!  Can this be done with MASM 7.x?

ALSO, I am reading about CodeView debugger, and it says that this ships with MASM for free, is this CVPACK16.exe...hmmm?

UPDATE! I used debug.exe from the command-line and produced JEFF.COM, it is zipped (which makes it BIGGER) and attached.  :green  I will try to make this in MASM sometime soon.  To view the source code, drop to command line in same directory as JEFF.COM, and run debug jeff.com, then type u 100, VIOLA! the program appears.  type ? for more help with debug.

Just curious, but I am going to try out a bunch of stuff tonight,

Jeff C
:green

[attachment deleted by admin]
Title: Re: .exe file question
Post by: hutch-- on October 05, 2005, 03:44:13 AM
Jeff,

I confess to being truly rusty here but the rough distinction is like this. A COM file is a pure memory image that occurs within a single 64k segment that has both the code and the data addresses pointed at the same segment. The Program Segment Prefix is filled out by DOS and a com file has its contents loaded after the PSP, this is why you need the ORG 100h so that the program starts in the right place. EXE files are a bit more complicated as they are subject to different memory models but you have a distinct EXE header and depending on the model, use a wider range of segments.

CS and DS are common with EXE files but larger memory models use ES as well. An EXE file is able to use more than 64k of memory and there used to be routines for using FAR memory that tiled 64k memory blocks into large units. The addressing mode was basic two parts, a start segment followed by an OFFSET which could be up to 64k. A reasonable number of services were available through the DOS and BIOS interrupts and these ranged from screen output to file IO. You would be looking for Ralph Brown's interrupt list in terms of documentation and probably an old Intel document for the instructions.
Title: Re: .exe file question
Post by: GregL on October 05, 2005, 04:54:25 AM
Jeff,

A couple things that I remember is that you use .MODEL TINY and ORG 100h to produce a .com file with MASM.

I found a snippet:

.286
.model tiny

.code
   org 100h

entry:
   jmp start

   message db 'Hello World!$'

start:
   mov dx, offset message
   mov ah, 09
   int 21h

   mov ax, 4c00h
   int 21h

end entry


Don't forget you need a 16-bit linker.

Title: Re: .exe file question
Post by: MichaelW on October 05, 2005, 05:35:03 AM
Jeff,

For a COM program, the DOS program loader:
1. Allocates a memory block for the program.
2. Builds a PSP in the first 256 bytes of the memory block.
3. Loads the COM file immediately following the PSP.
4. Sets DS, ES, and SS to the segment address of the PSP.
5. Sets up a stack at the end of the memory block.
6. Pushes a zero word onto the stack.
7. Transfers control to the instruction at offset address 100h, effectively setting CS to the segment address of the PSP.

For an EXE file the loader sets DS and ES to the segment address of the PSP and CS and SS (and IP and SP) to values specified in the EXE header.

MASM 6.x can create any program that DEBUG can create, and I think it likely that 7.x can too.

Title: Re: .exe file question
Post by: OceanJeff32 on October 05, 2005, 09:37:53 AM
Thanks guys, I appreciate the help, I copied the file, and tried to create a .com file, AND I have the 16-bit linker provided in another forum.

BUT it says invalid object module, it creates the object module, but I can't get link16.exe to work, what command lines should I use to compile? and link?

I'll work on it, I've also got another trick up my sleeve...let you know if it works out.

later,

jeff c
:U
Title: Re: .exe file question
Post by: thomasantony on October 05, 2005, 10:56:27 AM
Hi,
   Try using the commands below:

ml /c your_file.asm
link16 /TINY your_file.obj

Thomas :U
Title: Re: .exe file question
Post by: OceanJeff32 on October 05, 2005, 11:23:18 AM
Same problem. I've tried a bunch of options...

later,

jeff c
:bg

UPDATE! It works with MASM615

Catch y'all later!
Title: Re: .exe file question
Post by: GregL on October 06, 2005, 12:23:37 AM
Jeff,

I think I remember reading that ML 6.x generates OMF format by default and ML 7.x generates COFF format by default. So with ML 7.x you would need to use the /omf switch. Have you tried that?

later:

I found it, with ML 6.15, the /omf switch was introduced and COFF became the default instead of OMF.