about void voids (Re: efopen

tim at ISM780B.UUCP tim at ISM780B.UUCP
Fri Nov 22 09:46:00 AEST 1985


> One thing which many Unix compilers support is the 'asm' statement, that is:
> proc()
> {
>         asm("mov        r0, r1");
> }
.
.
.
>         I'd sure like to see someone defend this particularly disgusting
> (but supported on our 4.1bsd system) "feature"!

On the vax it is disgusting, because you can't do much unless you know
how the compiler works.  But some implementations of asm make it quite
useful.  For example, in Megamax C for the Macintosh, the asm statement
works like this:

	asm {
		stuff
	};              /* don't remember if the ; is needed here */


Within the stuff, one may use the following constructs ( substitute
your favorite instruction for "move" )

	move    foo, bar        /* like C bar = foo; foo,bar are global */
	move    a6@(foo),a6@(bar)       /* like above, but foo,bar local */
	move    d7,d6           /* foo and bar are first and second register
				   variables in this function */

So I can write assembly code and access all my C variables.  This has
several advantages:

	1. I don't need an assembler.  I can just use C.  Plus I get
	   to use the C preprocessor on my assembly files this way.

	2. I can profile my C programs ( they provide a profiler ),
	   and rewrite the slow parts in inline assembly in a
	   convienient and efficient way.

	3. When doing assembly stuff, I can keep C control flow.

Of course, this is machine dependent...

						Tim Smith
						ihnp4!cithep!tim
						ima!ism780!tim



More information about the Comp.lang.c mailing list