-
-
Save macournoyer/302316 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// compile: gcc 0L.c | |
// example: | |
// ./a.out 00201320130 | |
// expanded: | |
// ./a.out \ | |
// 002 # LOAD R[0] = 2 \ | |
// 013 # LOAD R[1] = 3 \ | |
// 201 # ADD R[0] += R[1] \ | |
// 30 # PRINT R[0] | |
// should print: 5 | |
#include <stdio.h> | |
#define C(i) (*i-48) | |
#define I C(++i) | |
#define R reg[C(++i)] | |
main (int argc, char *argv[]) { | |
char reg[3], *i = argv[1]; | |
while (*i) { | |
switch (C(i)) { | |
case 0: R = I; break; // LOAD: R[A] = B | |
case 1: R = R; break; // MOVE: R[A] = R[B] | |
case 2: R += R; break; // ADD: R[A] = R[A] + R[B] | |
case 3: printf("%i\n", R); break; // PRINT: print(R[A]) | |
} | |
i++; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment