Arguments in included assembler instructions

Gregory Smith greg at utcsri.UUCP
Tue Jan 6 12:48:35 AEST 1987


In article <488 at l.cc.purdue.edu> cik at l.cc.purdue.edu (Herman Rubin) writes:
>
>Many times I have found it necessary to include asm instructions
>in a C program.  It should be possible to do this in such a way
>that the compiler will substitute the locations of variables for
>the variable names in the asm instructions.  I know of ways to do
>the job; one person to whom I showed this pointed out that if the
>compiler were changed this could break.  This would not be the case
>if the suggested enhancement were made.

Yes. Someone suggested a 'printf-like' capability for asm() a while back.
EG on a 68000 machine, to get the user stack pointer in supervisor code:

	... char *user_sp;
	...
	asm(" move usp,%a", user_sp );

'%a' would change either to (1) the appropriate extern name (eg "_user_sp"),
if user_sp were external, (2) the appropriate local symbol if user_sp were
local static, or (3) the appropriate stack-indexed or frame-indexed address
if user_sp were auto.

The above code would then be immune to a large class of compiler
changes. In particular, changes to (1) name translation conventions, (2) local
symbol allocation method, (3) stack allocation and addressing conventions.

Other bells and whistles could be added, but this would be the most
useful feature. Of course, different features would be useful with
different machines.



More information about the Comp.lang.c mailing list