next up previous
Next: About this document ... Up: Example2 Previous: LANCE Generated IR

Compiled code

#define STACKSIZE 1000
int stack[STACKSIZE];
int R0, R1, R2, R3, R4, R5, R6, R7;
int SP=0, BP=0;
void push(int element)
{
  stack[++SP]=element;
  return;
}
int pop()
{
  return(stack[SP--]);
}
int getint()
{
  int a;
  scanf("%d",&a);
  return a;
}
void putint(int a)
{
  printf("%d",a);
}
/* End of machine description */    

void add()
{
  push(BP);          /* Dynamic link */
  BP=SP;             /* set base(BP) to new activation record */
  SP=SP+1;           /* make space for local variables*/
  push(R0);          /* save registers */
  push(R1);
  push(R2);
  push(R3);
  push(R4);
  push(R5);
  push(R6);
  push(R7);

  R0=stack[BP-1]+stack[BP-2];
  stack[BP+1]=R0;      /*for local variable c*/
  stack[BP-3]=stack[BP+1];  /*assign return value */

  R7=pop();
  R6=pop();    
  R5=pop();    
  R4=pop();    
  R3=pop();    
  R2=pop();
  R1=pop();    
  R0=pop();    
  SP=SP-1;            /*restore SP*/
  BP=pop();
  return;
}

void my_main()
{
  push(BP);           /* Dynamic link */
  BP = SP;            /* set base of current activation record */
  SP = SP + 3;        /* make space for local variables*/
  push(R0);           /* save registers */
  push(R1);
  push(R2);
  push(R3);
  push(R4);
  push(R5);
  push(R6);
  push(R7);
                        /* assign local variables */
  stack[BP+1] = 9;      /* x_7 */
  stack[BP+2] = 7;      /* y_8 */
  /*stack[BP+3] = z-value */   /* z_9 */

  SP=SP+1;            /*make space for return value*/ /* t2 */
  push(stack[BP+2]);  /*push actual parameter*/
  push(stack[BP+1]);
 
  add();
  
  pop();              /*pop actual parameter*/
  pop();
  stack[BP+3] = stack[SP]; /* access return value */ /* t2 */
  SP=SP-1;
  putint(stack[BP+3]); 
  
  
  R7=pop();
  R6=pop();    
  R5=pop();    
  R4=pop();    
  R3=pop();    
  R2=pop();    
  R1=pop();
  R0=pop();    
  SP=SP-3;            /*restore SP*/
  BP = pop();         /* restore base pointer */
  return;
}


/* The driver
main()
{
  my_main();
}
*/



2006-03-18