Path: utzoo!utgpu!water!watmath!clyde!rutgers!mit-eddie!uw-beaver!uw-june!pardo From: pardo@june.cs.washington.edu (David Keppel) Newsgroups: comp.lang.c Subject: Portable "asm" (Was: The D Programming Language) Keywords: portable D Message-ID: <4257@june.cs.washington.edu> Date: 22 Feb 88 00:51:00 GMT References: <11702@brl-adm.ARPA> <243@eagle_snax.UUCP> <2245@geac.UUCP> <2327@umd5.umd.edu> <915@PT.CS.CMU.EDU> Reply-To: pardo@uw-june.UUCP (David Keppel) Organization: U of Washington, Computer Science, Seattle Lines: 51 In article <915@PT.CS.CMU.EDU> edw@IUS1.CS.CMU.EDU (Eddie Wyatt) writes: >> - we should assume that compilers for this language are going to >> do a great deal of optimisation; in particular, they will optimise >> across entire compilations, not just single files. > > Which brings up a question, what happens to the asm statement then. >If you have the write you code such that you have no idea >where variables are stored, how can you reliable use assemble statement >that play with storage. I think the conclusion will be trash asm. I think not. I think it will be to change the semantics of asm into a varargs function (which may even have the register allocator at its disposal?): void dumb_function( doit_to ) int *splat; { enum Labels { START = 1, LOOP, DONE }; extern int splodge; int r1, r2; _reg_alloc(2); asm( START, "movl", ADDR, &splodge, REG, r1 = _register() ); asm( 0, "clrl", REG, r2 = _register() ); asm( LOOP, "tstl", REG, r2 ); asm( 0, "bgeq" LAB, DONE ); asm( 0, "addl", ADDR, sizeof( some_type ), REG, r1 ); asm( 0, "subl", ADDR, sizeof( some_type ), ADDR, splat ); asm( 0, "brb", LOOP ); asm( DONE, NULL ); _reg_unalloc(); /* r1 is just thrown away ... */ } Alternatively, the opcode could specify the format of the arguments that it takes (much as printf works), but I think this is unnatural, since if you had a bunch of typedefs, you couldn't just do: #ifdef VAX #define ADD "addl" #else #define ADD "add" #endif (or something slightly less sick, but I hope this puts the idea across). No, I haven't thought to closely about this, there may be some fatal flaw. The worst thing is that this is almost portable ;-> ;-D on (Well, C is just portable SNOBOL ;-) Pardo