delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/10/28/15:50:16

From: "John S. Fine" <johnfine AT erols DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Mixing asm and C
Date: Wed, 28 Oct 1998 15:47:45 -0500
Lines: 44
Message-ID: <363782F1.7EA4@erols.com>
References: <363247ad DOT 81580547 AT newshost DOT cc DOT utexas DOT edu>
Mime-Version: 1.0
X-Trace: /+PtaL3CyGNp0PZWl2G+WOD60ZXFNKX/QtzeACFM7Fg=
X-Complaints-To: abuse AT rcn DOT com
NNTP-Posting-Date: 28 Oct 1998 20:48:31 GMT
X-Mailer: Mozilla 3.01 (Win95; U)
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Jeramie Hicks wrote:
> 
> I've been working on this code for about a week now with no result.
> Could somebody point out what I'm doing wrong? All I want to do is
> load a COM program into a chunk of allocated memory and then run it.
. . .
> // allocate comdata to size of COM program
> // fread COM program into comdata
> codeptr = (functptr) comdata;
> codeptr();

> and then, the COM program compiled with MASM 6.1 with the /AT switch:
> 
> .model TINY
> .386
> .code
> equalfive proc
>         mov eax, 5
>         ret
> equalfive endp
> end equalfive

  I may not be remembering MASM switches and directives correctly, but
I am nearly sure that .model TINY _always_ forces 16-bit defaults.
Most instructions generated that way will not run correctly when
the CPU is in 32-bit mode (as it is with DJGPP).

  You need code in what is called "FLAT" model, but I don't know
whether MASM can make a .COM file in FLAT model, or whether
FLAT model forces it to make .obj's intended only for windows
programs.

  I wrote my own linker (JLOC) in part because the Microsoft tools
make so many assumptions about what you OUGHT to be doing.  My
linker makes it easy to convert .obj files to the kind of flat
.COM format you want.  In this case it is probably possible to
get the Microsoft linker to do it as well.  Regardless, you first
need to make the assembler generate 32-bit code rather than 16-bit
code.  The cleanest way to do that is get rid of the ".model" and
".code" directives and write your own SEGMENT directive including
"USE32" to make sure it is making 32-bit code.
-- 
http://www.erols.com/johnfine/
http://www.geocities.com/SiliconValley/Peaks/8600/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019