[comp.lang.c] "Portable" asm

pardo@june.cs.washington.edu (David Keppel) (03/09/88)

Assuming that you want asm...

To increase the portability of the "asm" directive, there should
be some way of telling the compiler which globals, which special
registers, etc. you want to use.  The syntax is bogus, but here's
the idea:

  + state (prototype) all the resources you need
  + hide access to everything else

    #include <asm.h>

    struct foo { ... }	glob1, glob2;

    anotherfunc() { ... }

    myfunc()
    {
	int	locvar;

	/* code */

	start_asm( glob1, glob2, anotherfunc, asm_tmps(3), locvar ) {
#ifdef ASM_VAX
	    /* high-level assembly code goes here */
#elseif ASM_MC68000
	    /* high-level assembly code goes here */
#else
	    ASM_FAILED
#endif
	}

	/* code */
    }


	;-D on  (The program is dead, but the code lives on)  Pardo

pardo@june.cs.washington.edu (David Keppel) (03/29/88)

shebs%defun.utah.edu.UUCP@utah-cs.UUCP (Stanley T. Shebs) writes:
>>[ "high-level" assembly language ]
>Gee, and I thought it was the explicit management of registers and memory
>that made assembly programming such a chore!  CAL (Cray Assembly Language)
>is infix, but I hadn't noticed that it made much difference to anybody.
>
>In case anybody hadn't realized it, this is the same Herman Rubin that's
>been calling for "portable assembly languages" for years.  The suggestion
>that such a desire is self-contradictory doesn't seem to bother him.

Register allocation technology is pretty well understood (if slightly
NP-complete, a.k.a. slightly pregnant), so there shouldn't be much problem
in doing automatic symbolic management (with "pragma" and "insist"
facilities for cases when particular registers must be used).

The IBM PL.8 compiler has a RISC-like "assembly" language IR and
succesfully produces assembly code for a variety of processors including
the 801 and the 68000.  There are also a bazillion cross-assemblers, some
of which produce good code.

Self contradictory?  No, you just need to know that (a) you still have to
be able to drop in to "native" assembly at times and that (b) like HLLs,
the resulting code isn't always as good as it could be.

In general the thing that differentiates an assembler from a compiler is
the simplicity of the mapping from source statements to output code.

	;-D on  ( *Damn*.  Another $0.02 down the drain. )  Pardo