Skip to content

Instantly share code, notes, and snippets.

@macournoyer
Created February 12, 2010 04:56
Show Gist options
  • Save macournoyer/302316 to your computer and use it in GitHub Desktop.
Save macournoyer/302316 to your computer and use it in GitHub Desktop.
// 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