/* This program simulates the behavior of stack4.c. */ #include int stack[50]; int *stackpointer = stack + 50; double returnvalue; int main(void) { /* printf("20 factorial is %f\n",factorial(20)); */ stackpointer -= 1; stackpointer[0] = 271; stackpointer -= 1; stackpointer[0] = 20; goto factorial; instruction271: printf("20 factorial is %f\n",returnvalue); /* return 0; */ return 0; factorial: #define n (stackpointer[0]) /* printf("n is %d; &n is %u\n",n,(unsigned int) &n); */ printf("n is %d; &n is %u\n",n,(unsigned int) &n); /* if (!n) return 1; */ if (!n) { returnvalue = 1; stackpointer += 2; goto returnaddress; } /* return n * factorial(n - 1); */ stackpointer -= 1; stackpointer[0] = 314; stackpointer -= 1; stackpointer[0] = stackpointer[2] - 1; goto factorial; instruction314: returnvalue = n * returnvalue; stackpointer += 2; goto returnaddress; returnaddress: switch(stackpointer[-1]) { case 271: goto instruction271; case 314: goto instruction314; } }