Mail Archives: djgpp/2001/04/16/17:00:15
From: | "Tom Hunt" <thunt1 AT falcon DOT lhup DOT edu>
|
Newsgroups: | comp.os.msdos.djgpp
|
Subject: | Using MASM generated COFF files with GPP (solution)
|
Date: | Mon, 16 Apr 2001 16:45:01 -0400
|
Organization: | East Stroudsburg University, Pennsylvania
|
Lines: | 47
|
Message-ID: | <9bflht$l1$1@jake.esu.edu>
|
NNTP-Posting-Host: | thunt1.lhup.edu
|
X-Priority: | 3
|
X-MSMail-Priority: | Normal
|
X-Newsreader: | Microsoft Outlook Express 5.50.4133.2400
|
X-MimeOLE: | Produced By Microsoft MimeOLE V5.50.4133.2400
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
Reply-To: | djgpp AT delorie DOT com
|
I posted a question about this a while back and just found a solution to the
problem. If someone posts a similar question in the future, this will fix
it.
say we're writing a function foo and assembling it with MASM using the
command line
ml /c /coff foo.asm
MASM will generate an object file instead of an exe file in COFF format
instead of its usual OMF format.
The foo.asm file should look something like this:
.386P ; use protected mode 386 instead of real mode 386
.model flat ; flat memory model for protected mode
public _foo ; tells the assembler and linker that another module needs
this function
.code
_foo proc
push ebp
mov ebp, esp
... ; guts of the function goes here
mov eax, [return_value] ; the return value should go into al, ax,
; or eax depending on the
; size of the return value
mov esp, ebp
pop ebp
ret ; do not put a number after ret to fix stack, the C++
program will take care of it
_foo endp
end ; no main function in the assembly module
The C++ file that uses foo needs to declare foo as an extern like:
extern "C" int foo(...); // declare the parameters and return value here
that's all there is too it. When I compiled the whole thing, the link phase
took a lot longer than it usually does, so just minimize the dos window
you're using if you're running Windows and do something else for a bit.
Tom
- Raw text -