[comp.os.msdos.programmer] Calling .ASM from .C ?

a50@mindlink.UUCP (Cliff Lum) (08/09/90)

If you have Masm 5.1 you should have the documentation for mixed language
programming which will tell you how to call an ASM program from C.
If you use the new segemnt directives which I know will work with Microsoft C.
You would go DOSSEG
.MODEL SMALL,C          ;depending on the model required
                        ;the C sets up the stack for proper returns
.CODE
PUBLIC  hello
hello   PROC
        ...
        code
        ret
hello   ENDP

If yopu do not use the masm simplified directive you have save the bp register
on the stack and it depends on the model you use.

TOMIII@MTUS5.BITNET (Thomas Dwyer III) (08/09/90)

Hi there.  I have RTFM many times over and still cannot grasp the idea of
how to call an assembly procedure from Turbo C (I have TC v1.5 & MASM 5.1).
Suppose I have two trivial programs, TEST.C and HELLO.ASM as follows:

TEST.C
------

extern hello();

main()
{
       hello();
}


HELLO.ASM
---------

_text  segment         public
       org             100h
       assume          cs:_text,ds:_text

start:
       call            _hello
       mov             ax,4c00h
       int             21h

msg:   db              13,10,"Hello world.",13,10,"$"

       public          _hello
_hello proc
       mov             ah,9
       mov             dx,offset msg
       int             21h
       ret
_hello endp

_text  ends
       end             start


The question is, how to I hack up HELLO.ASM so that I can link it with
TLINK?  Does my "hello" need to be prefixed in my "extern" statement?
I tried it both ways.  Any insight on the matter would be most appreciated.

Thanks,
Thomas Dwyer III                            TOMIII   @ MTUS5.BITNET
Network Programmer                          DWYERIII @ MTUS5.BITNET
Computing Technology Services
Michigan Technological University

david@gisatl.FIDONET.ORG (David Deitch) (08/11/90)

In a message of <Aug 08 22:46> Thomas Dwyer III (TOMIII@MTUS5.BITNET ) 
writes:

     Let me preface this by saying that I work with MSC not Turbo C, 
but I believe it will still hold true.


 > TEST.C
 > ------

 > extern hello();

 > main()
 > {
 >        hello();
 > }


     Do you need the () on your external declaration?


 > HELLO.ASM
 > ---------

 > _text  segment         public
 >        org             100h
 >        assume          cs:_text,ds:_text

     Why use the org line?  That is supposed to be for when you are 
creating a .COM program, not an object file that will be linked into a 
C program.

 > start:
 >        call            _hello
 >        mov             ax,4c00h
 >        int             21h

 > msg:   db              13,10,"Hello world.",13,10,"$"

     It appears you want to run your program both ways.  I do not 
think you can do this.  It either has to be .COM (start:) or object 
(_hello).

 >        public          _hello
 > _hello proc
 >        mov             ah,9
 >        mov             dx,offset msg
 >        int             21h
 >        ret
 > _hello endp

 > _text  ends
 >        end             start


Try not using the _ in hello.  I do not in MSC.

 > The question is, how to I hack up HELLO.ASM so that I can link it 
with
 > TLINK?  Does my "hello" need to be prefixed in my "extern" 
statement?
 > I tried it both ways.  Any insight on the matter would be most 
 > appreciated.

     I just hope I am semi-accurate.  This is not my forte!

     David Deitch (GIS)
          deitch@gisatl.fidonet.org
               1:133/411@fidonet
 
 


--  
-----------------------------------------------------------------------------
David Deitch - via FidoNet node 1:133/411
UUCP: galbp!gisatl!david
INTERNET: david@gisatl.FIDONET.ORG