Go backward to The language accepted by c--
Go up to Top
Go forward to Footnotes

The Inline Statement

Finally, c-- includes a primitive facility for explicitly inserting specific machine instructions in the code it generates. The compiler translates C code into 34000 assembly language which is then passed to the wc34asm program to produce a tmem file. A statement of the form
inline( string-constant )
will cause the compiler to insert the assembly language code found in the file named by the string constant in the place where it would have generated code if a normal statement had appeared instead of the inline.

To illustrate the use of this statement, consider the problem of implementing a function "putnum" to output integers. In order to output a number on the 34000, one simply needs to execute an OUTNUM instruction. Unfortunately, none of the standard constructs of C will cause the compiler to output an OUTNUM instruction. The solution is to put the assembly language code for the appropriate OUTNUM instruction in a file named "putnum.s" and then include the following definition for "putnum" in your C source file: (1)

putnum( value )
int value;
{
	inline( "putnum.s" );
}
The code generated by the compiler for this function will execute the necessary instructions to establish the function's environment (i.e. a LINK instruction), then execute the code in the "putnum.s" file and finally execute instructions to return from the function (UNLK and RTD).

In order to make this work, one merely needs to include in "putnum.s" an OUTNUM which will print the value of the function's parameter "value". But how can you determine how to reference the location in which "value" is store from the assembly code?

When a file is compiled using c--, the compiler produces an assembly language listing of the translation it produced. For example, if you type

c-- prog.c
a file name "prog.l" will be produced containing the listing. Within the assembly code, the compiler includes STAB directives that provide information to the debugger about variables defined in the procedure. A complete discussion of these STAB directives can be found in the handout "The WC34000 Assembler". For our purposes, however, all you need to know is that for each local variable or parameter declared in a function there will be an STAB directive including its displacement relative to the frame pointer register (A6). For example, the STAB directive for "value" would look like:
	STAB	LOCVAR,"value",offset=2,type ="I" 
The value given as "offset" gives the displacement to "value". Thus, you can compile the file containing the definition of "putnum" before including the inline statement and then examine the ".l" file produced to determine what operands to use in the "putnum.s" file.

In this case, since "value" is at displacement 2 relative to A6, the file "putnum.s" should consist of the single line:

	OUTNUM	2(A6)


Prev Up Next