Hacker News new | past | comments | ask | show | jobs | submit login

Not quite, but an interpreter can be written in less than 100 bytes of x86 instructions:

http://www.hugi.scene.org/compo/compoold.htm#compo6




The competition rules have added constraints to make the interpreter a usual command line tool. However, with memory mapped input and output ports it becomes a lot easier, which would be akin to 8bit micro controller programming. Parsing would take more than one cpu instruction per BF instruction, so the program would need to be assembled. I don't know x86 well enough to write that, though. I imagined, there would be a single instruction equivalent of 'x=*(p++)', but couldn't find anything like that.

In some makeshift syntax and with one instruction too much, I got:

   >, < = inc, dec al
   +, - = inc, dec [al]
   . = out output_port, [al]
   , = in [al], input_port
   [ = Label: cmp [al], #0
       jnz (Labelend + sizeof (jmp instruction))
   ] = Labelend: jmp Label
The labels are generated by the assembler. The ports would have to be directly soldered to some I/O peripherie, but alternatively the input and output could be memory mapped and fed by interrupts, as well.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: