DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
Enhanced asm facility

Definition

The syntactic descriptions that follow are presented in the style used in ``C language compilers''. The syntactic classes type-specifier, identifier, and parameter-list have the same form as in that topic. A syntactic description enclosed in square brackets (``[ ]'') is optional, unless the right bracket is followed by ``+''. A ``+'' means ``one or more repetitions'' of a description. Similarly, ``*'' means ``zero or more repetitions.''

   asm macro:
   	asm [ type-specifier ] identifier ( [ parameter-list ] )
   	{
   	[ storage-mode-specification-line
   		asm-body ] *
   	}

An asm macro consists of the keyword asm, followed by what looks like a C function declaration. Inside the macro body there are one or more pairs of storage-mode-specification-line(s) (patterns) and corresponding ``asm-body(ies)''. If the type-specifier is other than void, the asm macro should return a value of the declared type.

   storage-mode-specification-line:
   	% [ storage-mode [ identifier [ , identifier ]* ] ; ]+

A storage-mode-specification-line consists of a single line (no continuation with \ is permitted) that begins with % and contains the names (identifier(s)) and storage mode(s) of the formal parameters. Modes for all formal parameters must be given in each storage-mode-specification-line (except for error). The % must be the first character on a line. If an asm macro has no parameter-list, the storage-mode-specification-line may be omitted.

Storage modes

These are the storage modes that the compiler recognizes in asm macros.


treg
A compiler-selected temporary register.

ureg
A C register variable that the compiler has allocated in a machine register.

reg
A treg or ureg.

con
A compile time constant.

mem
A mem operand matches any allowed machine addressing mode, including reg and con.

lab
A compiler-generated unique label. The identifier(s) that are specified as being of mode lab do not appear as formal parameters in the asm macro definition, unlike the preceding modes. Such identifiers must be unique.

error
Generate a compiler error. This mode exists to allow you to flag errors at compile time if no appropriate pattern exists for a set of actual arguments.

For the storage mode %con, asm allows you to impose conditions over the value of the constant using the following operators: <, <=, >, >=, !=, ==, %, and !%. For example:


% con x==0
expand if x equals zero.

% con x<16,y==0
expand if x is less than 16 and y equals zero.

% con x%4
expand if x mod 4 is not zero.

% con x!%4
expand if x mod 4 is zero.

asm body

The asm body represents (presumed) assembly code that the compiler will generate when the modes for all of the formal parameters match the associated pattern. Syntactically, the asm body consists of the text between two pattern lines (that begin with %) or between the last pattern line and the } that ends the asm macro. C language comment lines are not recognized as such in the asm body. Instead they are simply considered part of the text to be expanded.

Formal parameter names may appear in any context in the asm body, delimited by non-alphanumeric characters. For each instance of a formal parameter in the asm body the compiler substitutes the appropriate assembly language operand syntax that will access the actual argument at run time. As an example, if one of the actual arguments to an asm macro is x, an automatic variable, a string like 4(%fp) would be substituted for occurrences of the corresponding formal parameter. An important consequence of this macro substitution behavior is that asm macros can change the value of their arguments. Note that this is different from standard C semantics.

For lab parameters a unique label is chosen for each new expansion.

If an asm macro is declared to return a value, it must be coded to return a value of the proper type in the machine register that is appropriate for the implementation.

An implementation restriction requires that no line in the asm body may start with %.


Next topic: Writing asm macros
Previous topic: Using asm macros

© 2005 The SCO Group, Inc. All rights reserved.
SCO OpenServer Release 6.0.0 -- 02 June 2005