[comp.lang.c] Inline assembler in Microsoft C ????

vic@zen.UUCP (06/09/87)

I'm using Microsoft C version 4.0 on an HP Vectra running DOS 3.2

Can anyone tell me if there is an "inline" assembler capability for this
compiler. I can't find any mention of anything like this in the documentation
but it would help me a great deal when interfacing to existing m/code routines.

I have heard of C compilers where you could do things like:


#asm
   <assembler code>
#endasm


asm("<assembler code>");



Any help would be much appreciated.

--

Victor Gavin						Zengrange Limited
vic@zen.co.uk						Greenfield Road
..!mcvax!ukc!zen.co.uk!vic				Leeds
							England
+44 532 489048						LS9 8DB

pozar@hoptoad.uucp (Tim Pozar) (06/16/87)

In article <608@zen.UUCP> vic@zen.UUCP (Victor Gavin) writes:
>
>I'm using Microsoft C version 4.0 on an HP Vectra running DOS 3.2
>
>Can anyone tell me if there is an "inline" assembler capability for this
>compiler. I can't find any mention of anything like this in the documentation
>but it would help me a great deal when interfacing to existing m/code routines.
>
>I have heard of C compilers where you could do things like:
>
>
>#asm
>   <assembler code>
>#endasm
>
>
>asm("<assembler code>");
>

   Isn't this spo'sta be apart of the "Standard C".  I seem to remember
it being metioned in the K&R.

-- 
        Tim Pozar
UUCP    pozar@hoptoad.UUCP
Fido    125/406
USNail  KLOK-FM
	77 Maiden Lane
	San Francisco CA 94108

guy@gorodish.UUCP (06/16/87)

> >asm("<assembler code>");
> 
>    Isn't this spo'sta be apart of the "Standard C".  I seem to remember
> it being metioned in the K&R.

It is absolutely NOT supposed to be in standard C!

	1) One could imagine an implementation of C on a machine with
	   no "assembly language".

	2) Not all C compilers generate assembly language; it may be
	   very tricky to generate in-line assembly language with
	   some of them.

	3) Not all C compilers handle this in the same fashion.  The
	   VAX compiler, and a lot of other compilers, have the
	   syntax

		asm(string);

	   and just squirt the string into the generated code at that
	   point, *verbatim*.  Others permit you to define in-line
	   "functions" that take arguments, and have different code
	   generated depending on the addressing mode used to refer
	   to the arguments; in these versions, "asm" is used in the
	   *declaration*, and the "function" is *used* just like a
	   regular function.

	4) Standardizing this would have minimal effect on
	   portability, as should be obvious.

	5) The only place in the Reference Manual portion of K&R (the
	   only part that counts when talking about "Standard C")
	   where "asm" is mentioned merely states that some
	   implementations reserve "asm" as a keyword - not that all
	   of them do, and not that all of those that do use it in
	   the same way.
	Guy Harris
	{ihnp4, decvax, seismo, decwrl, ...}!sun!guy
	guy@sun.com

platt@emory.UUCP (Dan Platt) (06/17/87)

In article <2299@hoptoad.uucp> pozar@hoptoad.UUCP (Tim Pozar) writes:
>In article <608@zen.UUCP> vic@zen.UUCP (Victor Gavin) writes:
>>
>>I'm using Microsoft C version 4.0 on an HP Vectra running DOS 3.2
>>
>>Can anyone tell me if there is an "inline" assembler capability for this
>>compiler. I can't find any mention of anything like this in the documentation
>>but it would help me a great deal when interfacing to existing m/code routines.
>>
>>I have heard of C compilers where you could do things like:
>>#asm
>>   <assembler code>
>>#endasm
>   Isn't this spo'sta be apart of the "Standard C".  I seem to remember
>it being metioned in the K&R.

K&R refer to assembler only on page 180 (to the best of my knowlege) where
they state that the keyword 'asm' is reserved by some implementations (no
other comments).

Having done a fair amount of C/Assembler interfacing (using MS C 4.0)
I can say that it's not too much of a burden to write the code, and
link the .obj modules in at link time.  It also gives you more control
over how and where your data is treated and stored.

I've heard that the Turbo C has the inline capability. 

Dan

rosen@mtgzz.UUCP (t.rosenfeld) (06/29/87)

In article <2093@emory.UUCP>, platt@emory.UUCP writes:
> In article <2299@hoptoad.uucp> pozar@hoptoad.UUCP (Tim Pozar) writes:
> >In article <608@zen.UUCP> vic@zen.UUCP (Victor Gavin) writes:
> >>
> >>Can anyone tell me if there is an "inline" assembler capability for this
> >>compiler.
> Having done a fair amount of C/Assembler interfacing (using MS C 4.0)
> I can say that it's not too much of a burden to write the code, and
> link the .obj modules in at link time.  It also gives you more control
> over how and where your data is treated and stored.
> 
> Dan

As Dan writes MS tells you how to interface to assembly routines, but you 
probably would rather have inline code than be forced to do a CALL to
an assembly routine.

As far as I know there is no #asm directive in 4.0 but I think I heard there
will be in 5.0. One way to get around this is to compile your C code and have
the compiler generate the assembly module. (I think this is the -Fs option.)
Then enter your inline assembly at the correct loaction, assemble and link.
Of course if you ever want to edit the C source again you hac=ve to do it all
over again. 

This trick is also usefull to generate the corect compiler
directives to link an assembly function to the rest of your C  program.
That is write a null C funtion (e.g. ass_fun(){}) and then compile
with -Fs and then insert your assembly into the .asm file.

WARNING: When using the MS C 3.0 version in large model mode I ran into
a bug were the .asm file prodused by the -Fs option was wrong. Sometimes
it would not link, or worse yet it would link but the segment registers would
be wrong. I think I found the file was OK except it loaded SS with  _DATA
instead of DGROUP.

-- 
Tom Rosenfeld	 	@ AT&T Information Systems Labs, Middletown, NJ
			(201) 957-5867 	
			UUCP:		{harpo,ihnp4,burl,akgua}!mtgzz!rosen
Disclaimer: I don't claim anything.

rosen@mtgzz.UUCP (t.rosenfeld) (06/29/87)

[Sorry for the multiple posting screw up.]

In article <2093@emory.UUCP>, platt@emory.UUCP writes:
> In article <2299@hoptoad.uucp> pozar@hoptoad.UUCP (Tim Pozar) writes:
> >In article <608@zen.UUCP> vic@zen.UUCP (Victor Gavin) writes:
> >>
> >>Can anyone tell me if there is an "inline" assembler capability for this
> >>compiler.
> Having done a fair amount of C/Assembler interfacing (using MS C 4.0)
> I can say that it's not too much of a burden to write the code, and
> link the .obj modules in at link time.  It also gives you more control
> over how and where your data is treated and stored.
> 
> Dan

As Dan writes MS tells you how to interface to assembly routines, but you 
probably would rather have inline code than be forced to do a CALL to
an assembly routine.

As far as I know there is no #asm directive in 4.0 but I think I heard there
will be in 5.0. One way to get around this is to compile your C code and have
the compiler generate the assembly module. (I think this is the -Fs option.)
Then enter your inline assembly at the correct loaction, assemble and link.
Of course if you ever want to edit the C source again you hac=ve to do it all
over again. 

This trick is also usefull to generate the corect compiler
directives to link an assembly function to the rest of your C  program.
That is write a null C funtion (e.g. ass_fun(){}) and then compile
with -Fs and then insert your assembly into the .asm file.

WARNING: When using the MS C 3.0 version in large model mode I ran into
a bug were the .asm file prodused by the -Fs option was wrong. Sometimes
it would not link, or worse yet it would link but the segment registers would
be wrong. I think I found the file was OK except it loaded SS with _DATA
instead of DGROUP.
-- 
Tom Rosenfeld	 	@ AT&T Information Systems Labs, Middletown, NJ
			(201) 957-5867 	
			UUCP:		{harpo,ihnp4,burl,akgua}!mtgzz!rosen
Disclaimer: I don't claim anything.