[net.lang.pascal] Turbo External Assembler Routines

donw@zinfandel.UUCP (Don White) (12/12/85)

From postnews Wed Dec 11 17:35:52 1985
Subject: turbo and assembler
Newsgroups: 
     _
*** /o\
**  | <unch munch  
*** \_/ 

   I saw a query a few weeks ago about interfacing Turbo Pascal and
assembler routines. I have an answer but i haven't had time to post it 
until now. For those as would want to know, I am work in MSDOS.
   Mixing Turbo and assembler is not real easy. When the book refers to 
assembler routines needing to be "relocateable", it means that you cannot
declare a data segment in your assembler routine. But don't panic. There
is a way around this. But first the reason.
   Since turbo does not allow linking of object files, you will have to 
compile your assembler routines as stand-alone chunks of code, then link
your object file, then use the DOS function EXE2BIN to make a COM file
which can be accessed by turbo programs with EXTERNAL.
   The reason you cannot use a DATA segment in your code is because you
are stuck with the turbo DATA segment. If you write to a location in 'your'
DATA segment you will write over turbos' DATA segment. Turbo might get
confused :-) Since you will already have LINKED your assembler code, your
DATA memory offsets will not match the offsets of wherever Turbo places
your code.
   The way around this is to make a DATA area inside your CODE segment.
This just takes a few minutes on an editor. It is a minor change in your 
Assembler code and it allows you to take advantage of possible
assembler libraries.   
   There are a few other things you will need to know to handle the change
in environments. A header and trailer can be prepared which can be linked
to you routines to handle this.   
  
   You are going to be using Turbos' stack (and further there are problems
with making a COM file from an EXE file with a stack segment, check your DOS 
manual under EXE2BIN) so your code cannot have its own stack segment either.
   Using Turbos' stack is no problem as long as it is left the way it was 
before you started your assembler routine.


   I'm afraid i have to go for now but i will post an example soon as well as
the rest of the details on the "details" in the header and trailer.

   If you are in a hurry then send a SASE (Stamped Self Addressed Envelope 
in case i get swamped) to; 
 
                Don White
                P.O. Box 271177
                Concord Calif. 94527-1177  

    I will try to get your answer back in the mail the next day.


***************************************************************************
i am not responsible
and my company is not responsible
(my keyboard however :-)