/* This program simulates the behavior of stack1.c. */ #include int stack[20]; int *stackpointer = stack + 20; int main(void) { /* original code from stack1.c: one(); */ stackpointer -= 1; stackpointer[0] = 37; goto one; instruction37: /* two(); */ stackpointer -= 1; stackpointer[0] = 45; goto two; instruction45: /* one(); */ stackpointer -= 1; stackpointer[0] = 53; goto one; instruction53: /* two(); */ stackpointer -= 1; stackpointer[0] = 61; goto two; instruction61: /* return 0; */ return 0; one: /* int x = 1; */ /* int y = 2; */ /* int z = 3; */ stackpointer -= 3; #define x (stackpointer[0]) #define y (stackpointer[1]) #define z (stackpointer[2]) x = 1; /* in other words, stackpointer[0] = 1 */ y = 2; z = 3; /* printf("x is %d; &x is %u\n",x,(unsigned int) &x); */ /* printf("y is %d; &y is %u\n",y,(unsigned int) &y); */ /* printf("z is %d; &z is %u\n",z,(unsigned int) &z); */ printf("x is %d; &x is %u\n",x,(unsigned int) &x); printf("y is %d; &y is %u\n",y,(unsigned int) &y); printf("z is %d; &z is %u\n",z,(unsigned int) &z); /* x += 10; */ /* y += 10; */ /* z += 10; */ x += 10; y += 10; z += 10; /* return; */ stackpointer += 4; goto returnaddress; two: stackpointer -= 2; #define d (stackpointer[0]) #define e (stackpointer[1]) d = 4; e = 5; printf("d is %d; &d is %u\n",d,(unsigned int) &d); printf("e is %d; &e is %u\n",e,(unsigned int) &e); d += 10; e += 10; stackpointer += 3; goto returnaddress; returnaddress: switch (stackpointer[-1]) { case 37: goto instruction37; case 45: goto instruction45; case 53: goto instruction53; case 61: goto instruction61; } }