cvs.gedasymbols.org/archives/browse.cgi   search  
Mail Archives: djgpp/1998/03/23/22:14:12

Date: Mon, 23 Mar 1998 19:13:29 -0800 (PST)
Message-Id: <199803240313.TAA27307@adit.ap.net>
Mime-Version: 1.0
To: "John Shonder" <shonderja AT ornl DOT gov>, djgpp AT delorie DOT com
From: Nate Eldredge <eldredge AT ap DOT net>
Subject: Re: Using assembly language with DJGPP

At 04:31  3/23/1998 -0500, John Shonder wrote:
>I wrote a Turbo Pascal program that uses assembly language subroutines to
>speed up some numerical computations. I'd like to do the same thing using
>DJGPP but have no idea where to begin. I'd appreciate it if someone could
>help me out or point me to a source for this information.
>
>Here's how I did it in Turbo Pascal: Say I have a function "func" which
>takes two variables as arguments and returns another variable of the same
>type. Turbo Pascal  pushes pointers to the arguments onto the stack from
>left to right, so at the beginning of the assembly code I just popped those
>pointers into the appropriate variables and made the calculations. BTW these
>are structured variables so they're passed by reference not by value.
>
>I compile the assembly routine into an .obj file, and in the Pascal program
>there's a line like this:
>
>    function func(x,y,z: MyVarType);
>    {$L func.obj)
>
>Can I do something similar with DJGPP? What is the stack going to look like
>when I enter the assembly routine?

I assume you're writing in C here. The stack looks something like this:

[Rightmost arg]
....
[Leftmost arg]
[Return address] <== ESP points here.

Note that each of these is 4 bytes, unless you pass structs or
floating-point values around. You might want to try to avoid that; it can
get complicated.

Your routine must save EBX, ESI, EDI, EBP, DS and ES.

You also need a declaration of the function in your C source. To do the
linking, assemble the asm to a .o file and link with it as usual. (See GCC
docs for more.)

Another good way to find out about this would be to look at the code output
by the compiler. You can get this by compiling with -S.

Nate Eldredge
eldredge AT ap DOT net



- Raw text -


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