[ while X (slot 0) is not 0
>> move to Z (slot 2)
[ loop sets Z to 0
-
]
< move to Y (slot 1)
[ if Y is nonzero, set Z to 1
- decrement Y
> move to Z
+ set Z to 1
> move to a slot which will be 0 and terminate the loop
[ not really necessary unless the next variable is indeterminate
-
]
] slot 3 is 0 and pointed to so loop terminates after 1 iteration
< move to X
- decrement X
]
>> point to Z
[ if Z is 1 then Y >= X
#If we are here, then Y >= X
[ set Z to 0 to terminate loop
-
]
]
####
> point to slot 1
[
- initialize slot 1 to zero
]
>> point to slot 3
[
- set slot 3 to zero
]
+ set slot 3 to 1
> point to slot 4
[
- initialize slot 4 to 0
]
<<<< point to X
[ while X
>>>>> point to Z
[
- set Z to 0
]
<<< point to Y
[ if Y is nonzero, set Z to 1
- decrement Y
>>> point to Z
+ Z = 1
< point to slot 4 which is always zero
] loop ends after one iteration
< point to either slot 1 or slot 3
[
if we are here then we are pointing to slot 3
<< point to slot 1
}
< point to X
- decrement X
]
>>>>> point to Z
[
Y >= X, do whatever here
< point to slot 4, always zero to terminate the loop
]
####
#include
#include
#define X 0
#define Y 2
#define Z 5
/*
slot 0: X
slot 1: always zero, let's us know X is before it
slot 2: Y
slot 3: always one, let's us know Y is before it
slot 4: always zero, used to terminate loops
slot 5: Z
*/
int main(int argc, char **argv)
{
short int vars[5];
short int *p = vars;
if(argc != 3)
{
fprintf(stderr, "Usage: %s X-value Y-value\n", argv[0]);
exit(1);
}
vars[X] = atoi(argv[1]); /* set X */
vars[Y] = atoi(argv[2]); /* set Y */
p++; /* point to slot 1 */
while(*p)
{
(*p)--; /* initialize slot 1 to zero */
}
p++;p++; /* point to slot 3 */
while(*p)
{
(*p)--; /* set slot 3 to zero */
}
(*p)++; /* set slot 3 to one */
p++; /* point to slot 4 */
while(*p)
{
(*p)--; /* initialize slot 4 to zero */
}
p--;p--;p--;p--; /* point to X */
while(*p) /* while X */
{
p++;p++;p++;p++;p++; /* point to Z */
while(*p)
{
(*p)--; /* set Z to 0 */
}
p--;p--;p--; /* point to Y */
while(*p) /* if Y is nonzero, set Z to 1 */
{
(*p)--; /* decrement Y */
p++;p++;p++; /* point to Z */
(*p)++; /* Z = 1 */
p--; /* point to slot 4 which is always zero */
} /* loop terminates after 1 iteration */
p--; /* point to either slot 1 or slot 3 */
while(*p)
{
/* if we are here, we are pointing to slot 3 */
p--;p--; /* point to slot 1 */
}
p--; /* point to X */
(*p)--; /* decrement X */
}
p++;p++;p++;p++;p++; /* point to Z */
while(*p)
{
printf("Y >= X\n");
p--; /* point to slot 4, always zero */
}
return 0;
}