6 karma · joined Aug 19, 2020 (6y ago) · 8 submissions
comment 1y ago · link · parent
http://h41379.www4.hpe.com/doc/84final/4527/4527pro.html#fir...
comment 1y ago · link · parent
comment 1y ago · link · parent
(Though I bet an optimising compiler would be a _little_ more complicated) ;)
comment 3y ago · link · parent
#include <stdio.h>
int main() {
int c;
printf("#include <stdio.h>\nint main() {\nchar a[30000] = {0}; char *p = a;\n");
while((c = getc(stdin)) != EOF) {
switch(c) {
case '>': printf("++p;\n"); break;
case '<': printf("--p;\n"); break;
case '+': printf("++*p;\n"); break;
case '-': printf("--*p;\n"); break;
case '.': printf("putchar(*p);\n"); break;
case ',': printf("*p = getchar();\n"); break;
case '[': printf("while (*p) {\n"); break;
case ']': printf("}\n"); break;
}
}
printf("return 0;}\n");
return 0;
}
(Though sorry to any BF fans if I've missed something in the implementation) ;-)comment 3y ago · link · parent
I recently wrote an 8bit style CPU simulator (with it's own simple but perfectly usable instruction set) and assembler, together they fit into 1000 lines of C... To be fair that's a fairly specific case where C works really well though!