Low-level Brainfuck

Building a Brainfuck translator in TurboAssembler.

To begin with, we will write an interpreter in a high-level language, for example, in Pascal.

Let’s write a program that outputs a character whose ascii-code corresponds to the number of +

Therefore, we only need the bf-commands + and .

    var
     data_mem: array[1..10] of integer;    // data array
     command_mem: string;                 // command array
     i: integer;                         // index of command array
     j: integer;                        // index of data array
    begin
     j:=1;                  
     readln(command_mem);       
     
     for i:=1 to length(command_mem) do begin   // in the cycle we process the string 
      if (command_mem[i]='+') then data_mem[j]:= data_mem[j]+1;
      if (command_mem[i]='.') then write(chr(data_mem[j]));
     end;
    end.

bf-code +++++++++++++++++++++++++++++++++. will issue !
(the ascii-code of the symbol ! is 33).

The efficiency of the program can be checked in online ide ideone.com.
Читать дальше →
Low-level Brainfuck
Source: habrahabr