ref: 1bdf54041fbe740c98bae75f879678141dc494c9
dir: /5551a.c/
#include <stdbool.h> #include <stdio.h> #include <string.h> #include "5551.h" int main(int argc, char* argv[]) { unsigned int inst, a, b, c; char string[32], op[4]; while(scanf("%s %[^\n;]%*c", op, string) > 0) { sscanf(string, "%u %u %u", &a, &b, &c); if(!strcmp(op, "DIE")) inst = DIE; if(!strcmp(op, "OUT")) inst = OUT; if(!strcmp(op, "NOT")) inst = NOT; if(!strcmp(op, "AND")) inst = AND; if(!strcmp(op, "NOR")) inst = NOR; if(!strcmp(op, "XOR")) inst = XOR; if(!strcmp(op, "SUB")) inst = SUB; if(!strcmp(op, "ADD")) inst = ADD; if(!strcmp(op, "SHR")) inst = SHR; if(!strcmp(op, "SHL")) inst = SHL; if(!strcmp(op, "PUT")) inst = PUT; if(!strcmp(op, "MOV")) inst = MOV; if(!strcmp(op, "LDM")) inst = LDM; if(!strcmp(op, "NTH")) inst = NTH; switch(inst) { /* no args */ case DIE: printf("%u\n", inst); break; /* one arg */ case NOT: case OUT: printf("%u %u\n", inst, a); break; /* two args */ case PUT: case MOV: case LDM: printf("%u %u %u\n", inst, a, b); break; /* three args */ case AND: case NOR: case XOR: case SUB: case SHL: case SHR: case ADD: case NTH: printf("%u %u %u %u\n", inst, a, b, c); break; /* should this ever happen? */ default: fprintf(stderr, "unkown instr.\n"); return -1; } } return 0; }