
Inline Assembly
3-27
3.9.5.3 Example 3
asm(“mac.%m0 %2, %o2” :
“=c” (acc) :
“0” (acc), “r” (val));
The example above adds the 32-bit product of the high and low 16 bits
of
val
to
acc
. Note that the high part of
val
is obtained with the
%o2
operand and that the accumulator is printed with the
%m0
operand. Also
note that
acc
is both an input and an output argument, and that the
constraint for
acc
when it appears as an output argument is
c
, an
accumulator, and when it appears as an input argument is
0
, which tells
the compiler that these two arguments must be in the same location. If
acc
is in r0 and
val
is in r3r2, the following code is generated:
mac.a r2, r3
3.9.5.4 Example 4
asm(“mov %%smode, %0” : :
“rn” (val));
The example shown above sets
%smode
to
val
. Note that
%smode
is not
specified as a clobbered register, because
%smode
has no meaning to the
compiler. If
val
is a symbolic constant with the value 3, the following
code is generated:
mov %smode, 3
You can find additional examples of using the
asm
directive in the header
file
N_Intrinsic.h
.
3.9.5.5 Example 5
asm(“bits %smode, 7”);
The example shown above sets bit 7 in
%smode
. This example illustrates
the general rule that if the assembly statement contains an argument (as
in Example 4, which contains the argument
%0
), a reference to a register
must contain an additional per cent (
%
) sign. Example 5 contains no
argument, so a single
%
preceding
smode
is used.