i960 Processor Compiler User's Guide
7-84
7
Sequential Template Expansion. The following is a C language program
that uses an
asm function with two expansion templates:
#define status_reg 0xFE00FF00
asm int poll(void)
{
% void return; tmpreg t; spillall;
ld status_reg, t; #first template
% reglit return; spillall;/* return the current status */
ld status_reg, return; #second template
% error;
}
#define DEVICE_READY 0x00000001
main()
{
extern void service_device();
poll(); /*clear status bits*/
while (1) {
if (poll() & DEVICE_READY)
service_device();
}
}
The first call of poll does not use the return value and therefore matches
the
void return control line, expanding the first template. The second
call uses the return value and therefore matches the
tmpreg return
control, expanding the second template.
In this example, loading the status register also clears the status, so the
poll function can be used just to clear the status if the function return
value is ignored. However, when the return value is ignored, the program
must still allocate a register into which it can load the temporary value.