[comp.os.msdos.programmer] .com and .exe files

Greg.Smith@bohemia.UUCP (Greg Smith) (11/01/90)

St>renaming .exe file to .com files, and .com to .exe.
St>Imagine my suprize
St>when they all still worked!  This is not right by my
St>knowledge of dos.
St>Btw, I am using dos 3.3 with 4dos 4.03a.
(If 4Dos 4.03a is around I would like to know.  I have 3.02a)
The extensions of the files are mainly there for our referance.  The way the 
computer differentiates (sp) between the files is the header at the 
beginning of the file.  on EXE's  an  "MZ" will be the first two bytes in 
the file, while com files start out with actual code.  Also, following the 
MZ is a Program Segment Prefix(PSP) which defines many other needs, and 
memory/stack useage terms.

                                         Greg  
 
--- QuickBBS 2.64 (Eval)
 * Origin: Bohemia BBS system (303)449-8946 (200:5000/301)

--  
Greg Smith - via MetroNet node 200:5000/301
For best results, reply via UUCP: ...!boulder!bohemia!Greg.Smith

lsalomo@hubcap.clemson.edu (lsalomo) (11/02/90)

From article <92.2730D05F@bohemia.UUCP>, by Greg.Smith@bohemia.UUCP (Greg Smith):
> The extensions of the files are mainly there for our referance.  The way the 
> computer differentiates (sp) between the files is the header at the 
> beginning of the file.  on EXE's  an  "MZ" will be the first two bytes in 
> the file, while com files start out with actual code.  Also, following the 
> MZ is a Program Segment Prefix(PSP) which defines many other needs, and 
> memory/stack useage terms.

Not meaning to start a big discussion, but following the .EXE id ('MZ' as
you pointed out) is a header (NOT THE PSP) which describes the size of the
code in pages, the entry point, etc. plus the relocation table which the
loader uses to do any segment fixups before jumping to the entry point.

Cheers,
Q - the "Q"uestor for knowledge (, a degree, etc.)

lsalomo@hubcap.clemson.edu
ibmman@clemson.clemson.edu
=============================================================================
"Gee Wally, I think there's something wrong with the Beaver."
=============================================================================

37KGLLQ@CMUVM.BITNET (Tony Papadimitriou) (11/05/90)

Joe Fischer writes:
>An EXE file is usually quite a bit larger than a .COM file that does
>the same thing, especially if the program is written to load fast and
>run fast, and nothing can run as fast as a straight forward .COM file.
               ^^^^^^^^^^^^^^^^^^^^^^^

Execution speed is irrelevant to the program's type (.COM or .EXE).

> . . .                               While .COM files can be produced
>in a number of different ways, an EXE file can only be produced by a
>compiler.                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.EXE programs can be produced in as many ways as .COM programs.  If
certain compilers happen to not support either .COM or .EXE files
that does not mean only a compiler can produce .EXE files.

del@fnx.UUCP (Dag Erik Lindberg) (11/15/90)

In article <27016@cs.yale.edu> buddington-paul@cs.yale.edu (Paul Buddington) writes:
>convert it to a .COM file and run it.  (The reverse is also true - you cannot
>run the .EXE file from which you generate a .COM file either.)  The problem

I just posted a contradiction of this in another newsgroup, isn't that
a coincidence?  Fact is, if the EXE file is produced correctly, it will
run as either an EXE or as a COM.  Zortech C, for example, generates
programs up to 64k which will run as either EXE or can be converted to
COM and run in that format.  See the end of this article for a small
example generated by Zortech C.

>addition, multi-segmented files can only be in the .EXE format.

This is also not strictly true.  It is true that you cannot have a
stack segment, but a data segment can be used, if you are tricky, allowing
your program to have 64k program and 64k combined stack/data.

Here is an EXE file that runs, and can also be converted to COM.  You
will just have to trust me when I say that larger, more complex programs
also work fine in either mode.

begin 664 hello.exe
M35I$  D    "  ( __\          0  '                           
M                                                            
M                                                            
M                                                            
M                                                            
M                                                            
M                        ZP&0^KAZ#04/ +D$ -/HC,D#P8[8C 9: 2:+
M'BP B1Y' 8O8*QY: 8D>K0 FBQX" "O8@?L $'(#N_\/B] #TT*Q!-/CCM"+
MXX'KP@* _P)S!KK" .G> ?NT,,TAHUP!/ )S!KKU .G, 08?%@>^@ #\K#+D
MB\B_P@+SI#+ JHS0CMA'@^?^B3ZE ,<%JE6^P@*[ @"L/#UU"H,^; $ = /H
M+P$*P'0_NB )/"!TYCP)=.(\(G0$/"=U!8K0BO!&@_M =@:Z$ 'I:P%.B;=A
M (/# JP*P'0/.L)T!#K&=?,RP(A$_^NNT>N)'F$!QP9C 6$ BQYL 0O;=0.[
M ""!^P "<P.[  *)'FP! QZE '(J@\,1<B6 X_")'JD B1ZK +$$T^N)'J< 
M QZM (X&6@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K0\BU8$S2%S!:-> 1O 
M7<-5B^R+7@2T/LTAZQR058OL5[16C-N.PXM^!NL&58OL5[1!BU8$S2%?77,#
MHUX!&\##58OLBUX$BU8&BTX(BD8*M$+-(7,&HUX!&\"97<-5'H/L+(OLB]6T
M&LTABU8RN08 M$[-(7(,BU8<BT8:@\0L'UW#HUX!&\"9Z_*+W(M? K@ 1,TA
M]7,?BL*8BL3#B]RX $.+5P+-(7(-]D<$ G2.T.ESBK@% .N"58GE5E>+=@2+
M1 8E)@"#^ )U.(-\! !U!H-\# !T+(L\BT0$*_AT%O]T#%=0_W0(Z/'^@\0(
M.\=T!(!,!B"+1 J)1 *+1 2)!.L%QT0"  #V1 8@= 6X___K C' 7UY=PP!5
MB^R+3@KC%597C-B.7@2+=@:.P(M^"/.DCMA?7EW#58OLBTX*XP]65XY&!(M^
M!HMV"/.D7UY=PU6+[(M>!+1(S2%S!:-> 3/ 7<-5B^S_=@3HY/^+Y0O ="Q7
MB]B.P(M.!.,?@>'_#W4#N0 0*4X$T>'1X='A,_^+Q_.KC, % !#KVE^+PUW#
M58OLCD8$M$G-(7,#HUX!&\!=PU6+[,1>!+1*S2%S Z-> 8O#7<-5B^Q65QZ.
M1@2.7@:+7@B+R^,G@>'_#W4#N0 0*]G1X='AT>$S_S/V\Z6,P 4 $([ C-@%
M !".V.O5'U]>7<-5B^R[__^T2,TA<@V.P+1)S2$>![O__^L*/0@ = 6C7@$S
MVXO#,]*Y! #1X-'2XOI=PP        !%4E)/4CH@3E5,3"!P;VEN=&5R %IO
M<G1E8V@@0R R+C P(&QI8G)A<GDL($-O<'ER:6=H=" H0RD@,3DX."PQ.3@Y
M(%,L('=R:71T96X@8GD@5V%L=&5R($)R:6=H=   8                   
M                                                            
M                        #0I3=&%C:R!/=F5R9FQO=PT*) T*3F]T(&5N
M;W5G:"!M96UO<GD-"B0-"D)A9"!S=&%C:R!S:7IE('!A<F%M971E<@T*) T*
M1$]3(#$N>'@@;F]T('-U<'!O<G1E9 T*) T*36%X(&]F(#,R(&%R9W,@86QL
M;W=E9 T*) T*3E5,3"!F=6YC=&EO;B!P;VEN=&5R#0HD         $AE;&QO
M(%=O<FQD+@H                          " ! ' !  !P 0T*2&5A<"!I
M<R!C;W)R=7!T960-"B0        ! 0   0            (! 0 !        
M    !@$"  $           "  0,  0            (!!  !            
M                                                            
M                                                            
M                                                            
M                                                            
8                                
 
end
-- 
del AKA Erik Lindberg                             uunet!pilchuck!fnx!del
                          Who is John Galt?

sonny@charybdis.harris-atd.com (Bob Davis) (11/15/90)

In article <773@fnx.UUCP> del@fnx.UUCP (Dag Erik Lindberg) writes:
>In article <27016@cs.yale.edu> buddington-paul@cs.yale.edu (Paul Buddington) writes:
>>convert it to a .COM file and run it.  (The reverse is also true - you cannot
>>run the .EXE file from which you generate a .COM file either.)  The problem
>
>I just posted a contradiction of this in another newsgroup, isn't that
>a coincidence?  Fact is, if the EXE file is produced correctly, it will
>run as either an EXE or as a COM.  Zortech C, for example, generates
>programs up to 64k which will run as either EXE or can be converted to
>COM and run in that format.  See the end of this article for a small
>example generated by Zortech C.
>
	Okay. I must be doing something wrong. For the following simple
assembly language program, if I MASM it and LINK it to produce HELLO.EXE
and then run HELLO.EXE, my system prints some garbage with the desired
"HELLO, WORLD." message embedded in it. And then my system hangs, requiring
reboot.
	If I EXE2BIN the HELLO.EXE file into HELLO.COM, then HELLO.COM
runs fine.
	Why won't my .EXE file run as well as my .COM file?

	Thanks.
;**************************************************************************
;
CodeSeg		segment
		assume cs:CodeSeg,ds:CodeSeg
;
		org	100h		;ORG for all COM programs.
;
;	Print Message:
Entry:		mov	dx,Offset Msg		;dx points to message.
		mov	ah,09h			;DOS Fcn. 09h=Display String.
		int	21h			;Display String via DOS.
;
;	Terminate program:
		int	20h
;
Msg:
		db	0Dh,0Ah
		db	'HELLO, WORLD.'
		db	0Dh,0Ah
		db	0Dh,0Ah,'$'
;
CodeSeg		ends
		end	Entry
______________________________________________________________________________
Bob Davis, UofALA'66   \\ INTERNET : sonny@trantor.harris-atd.com  |  _   _  |
Harris Corporation, ESS \\    UUCP : ...!uunet!x102a!trantor!sonny |_| |_| | |
Advanced Technology Dept.\\ AETHER : K4VNO          |==============|_/\/\/\|_|
PO Box 37, MS 3A/1912     \\ VOICE : (407) 727-5886 | I SPEAK ONLY | |_| |_| |
Melbourne, FL 32902        \\  FAX : (407) 729-2537 | FOR MYSELF.  |_________|

sverrehu@ifi.uio.no (Sverre Holmsen Huseby) (11/15/90)

In EXE-programs, DS should be set before referencing data.
Try this:

  Entry:   mov ax, cs
           mov ds, ax
           :



Sverre H. Huseby   (sverrehu@ifi.uio.no)
Student   -   University of Oslo, Norway