GORBITSA/bf-interpreter
Jump to navigation
Jump to search
Created by Gorbit99. Runs in ROM mode with char input/output, only positive numbers allowed (0-255)
>+[ Read in code until # ,>+++++++[-<----->]< [ If not # >>+< Setting up if +++++[-<------>]<[>]>>[<<<+>>>>]<<< If 'A' set to 1 -[>]>>[<<<++>>>>]<<< If 'B' set to 2 -----[>]>>[<<<+++>>>>]<<< 'G' to 3 --[>]>>[<<<++++>>>>]<<< 'I' to 4 ------[>]>>[<<<+++++>>>>]<<< 'O' to 5 ---[>]>>[<<<++++++>>>>]<<< 'R' to 6 -[>]>>[<<<+++++++>>>>]<<< 'S' to 7 -[>]>>[<<<++++++++>>>>]<<< 'T' to 8 -------------[>]>>[<<<+++++++++>>>>]<<< 'a' to 9 -[>]>>[<<<++++++++++>>>>]<<< If 'b' set to 10 -----[>]>>[<<<+++++++++++>>>>]<<< 'g' to 11 --[>]>>[<<<++++++++++++>>>>]<<< 'i' to 12 ------[>]>>[<<<+++++++++++++>>>>]<<< 'o' to 13 ---[>]>>[<<<++++++++++++++>>>>]<<< 'r' to 14 -[>]>>[<<<+++++++++++++++>>>>]<<< 's' to 15 -[>]>>[<<<++++++++++++++++>>>>]<<< 't' to 16 >>-<<[-]< [ If value is opcode [->+>+<<]>[-<+>] Copy opcode >------[--[<+>[+]]]< [, If has operand read it >>+++++[-<+++++++++>]+<[-<-[>>>]>>[-<[-]>>>>]<<<<] If number >[- >>[-<++>]<[->+++++<] Multiply result by 10 <<<---[->>>>+<<<<] Add current to result +>>] <<] >>>>[-<<<<+>>>>] >>>> ] >+< ]> ] <<<<<<<<<<<[<<<<<<<<<]>>>>>>>>>>>>>>>>+>>>>>>>>>+>+ [ Number each operation [->>>+>>>>>>+<<<<<<<<<]>>>[-<<<+>>>]>>>>>+>+ ] <->>+>>>>>+>>>>+ [[->+>>>>+<<<<<]>[-<+>]+>>>>+] Go back to op 0 <<<<[<<<<<]<<<<<<[<<<<<<<<<]>>>>>>>>> [ While we don't go past the last instruction <<<<<<< [->>+>+<<<]>>>[-<<<+>>>] >+<< Setting up if A: -[>]>>[- Copy N <<<[->+>>>>>>>>>>>>>+<<<<<<<<<<<<<<]>[-<+>] >>>>>->>>>>>>>> Copy N to memory [<[->>>>>>>>>+<<<<<<<<<]>>>>>>>>>>] <[->>>>>+<<<<<]>>>>> Go to memory N [-[->>>>>+<<<<<]>>>>>] Copy memory N <[->+>+<<]>[-<+>] Copy N back to program >[-<<<<<+>>>>>]<<< [<<[-<<<<<+>>>>>]<<<] <<[-<<<<<+>>>>>]<<<< [<[-<<<<<<<<<+>>>>>>>>>]<<<<<<<<] +<< ]<<< B: -[>]>>[ >>[<]<<[ If x is 0 Copy N <<<[->+>>>>+<<<<<]>[-<+>] Move N to beginning >>>>>[<[-<<<<<<<<<+>>>>>>>>>]<<<<<<<<] <[->>>>>>>>>+<<<<<<<<<]>>>>>>>>> Jump to position [-[->>>>>>>>>+<<<<<<<<<]>>>>>>>>>] <<<<<<<<<<<+< ]>-> ]<<< G: -[>]>>[ Copy N <<<[->+>>>+<<<<]>[-<+>]>>>> [-]>- Move N to memory <<[->>>>>>>>>+<<<<<<<<<]>>>>>>>>>>> [<<[->>>>>>>>>+<<<<<<<<<]>>>>>>>>>>>] Go to N <<[->>+<<]>>[-[->>>>>+<<<<<]>>>>>] Copy memory >>>[-<<<+>>>>+<]>[-<+>]<< Move back [<<[-<<<<<+>>>>>]<<<] <<[-<<<<<+>>>>>]<<<< [<[-<<<<<<<<<+>>>>>>>>>]<<<<<<<<] +<<<-> ]<<< I: -[>]>>[- Copy and add N <<<[->+>>>>+<<<<<]>[-<+>]>>> ]<<< O: -[>]>>[- Copy N <<<[->+>>>+<<<<]>[-<+>]>>>>>- Copy X <[-<<+>>>+<]>[-<+>] Move N and X to memory <<[->>>>>>>>>+<<<<<<<<<] >[->>>>>>>>>+<<<<<<<<<] >>>>>>>>>> [ <<[->>>>>>>>>+<<<<<<<<<] >[->>>>>>>>>+<<<<<<<<<] >>>>>>>>>> ] <<[->>>+<<<] >[->>>>>+<<<<<] >> Go to memory N [->>>>+<<<<]>>>> [-[->>>>>+<<<<<]<[->>>>>+<<<<<]>>>>>>] Store <<[-]>[-<+>] Go back <<[<<<<<]<<<<<<[<<<<<<<<<]+ <<<[->>+<<]> ]<<< R: -[>]>>[- >>,< ]<<< S: -[>]>>[- Null X >>[-] Copy N <<<<<[->+>>>>+<<<<<]>[-<+>]>>> ]<<< T: -[>]>>[- >>.< ]<<< a: -[>]>>[- Copy N <<<[->+>>>>>>>>>>>>>+<<<<<<<<<<<<<<]>[-<+>] >>>>>->>>>>>>>> Copy N to memory [<[->>>>>>>>>+<<<<<<<<<]>>>>>>>>>>] <[->>>>>+<<<<<]>>>>> Go to memory N [-[->>>>>+<<<<<]>>>>>] Copy memory N <[->+>+<<]>[-<+>] Copy memory N back to beginning of memory >[-<<<<<+>>>>>]<<< [<<[-<<<<<+>>>>>]<<<] <<[->>>>>+<<<<<]>>>>> Go to memory |N| [-[->>>>>+<<<<<]>>>>>]>>> Copy memory |N| [->+>+<<]>[-<+>]> Move memory |N| back >>[<<[-<<<<<+>>>>>]<<<] <<[-<<<<<+>>>>>]<<<< [<[-<<<<<<<<<+>>>>>>>>>]<<<<<<<<] +<< ]<<< b: -[>]>>[ >>[<]<<[ If x is 0 Copy N <<<[->+>>>>>>>>>>>>>+<<<<<<<<<<<<<<]>[-<+>] >>>>>->>>>>>>>> Copy N to memory [<[->>>>>>>>>+<<<<<<<<<]>>>>>>>>>>] <[->>>>>+<<<<<]>>>>> Go to memory N [-[->>>>>+<<<<<]>>>>>] Copy memory N <[->+>+<<]>[-<+>] Copy memory N back to beginning of memory >[-<<<<<+>>>>>]<<< [<<[-<<<<<+>>>>>]<<<] <<[->>>>>+<<<<<]>>>>> Go to memory |N| [-[->>>>>+<<<<<]>>>>>]>>> Copy memory |N| [->+>+<<]>[-<+>]> Move memory |N| back >>[<<[-<<<<<+>>>>>]<<<] <<[-<<<<<+>>>>>]<<<< [<[-<<<<<<<<<+>>>>>>>>>]<<<<<<<<] +[<[-<<<<<<<<<+>>>>>>>>>]<<<<<<<<] <[->>>>>>>>>+<<<<<<<<<]>>>>>>>>> Jump to position [-[->>>>>>>>>+<<<<<<<<<]>>>>>>>>>] <<<<<<<<<<<+< ]>-> ]<<< g: -[>]>>[- Null X >>[-]<< Copy N <<<[->+>>>>>>>>>>>>>+<<<<<<<<<<<<<<]>[-<+>] >>>>>->>>>>>>>> Copy N to memory [<[->>>>>>>>>+<<<<<<<<<]>>>>>>>>>>] <[->>>>>+<<<<<]>>>>> Go to memory N [-[->>>>>+<<<<<]>>>>>] Copy memory N <[->+>+<<]>[-<+>] Copy memory N back to beginning of memory >[-<<<<<+>>>>>]<<< [<<[-<<<<<+>>>>>]<<<] <<[->>>>>+<<<<<]>>>>> Go to memory |N| [-[->>>>>+<<<<<]>>>>>]>>> Copy memory |N| [->+>+<<]>[-<+>]> Move memory |N| back >>[<<[-<<<<<+>>>>>]<<<] <<[-<<<<<+>>>>>]<<<< [<[-<<<<<<<<<+>>>>>>>>>]<<<<<<<<] +<< ]<<< i: -[>]>>[- Copy N <<<[->+>>>+<<<<]>[-<+>]>>>>>- Copy X <[-<<+>>>+<]>[-<+>] Move N and X to memory <<[->>>>>>>>>+<<<<<<<<<] >[->>>>>>>>>+<<<<<<<<<] >>>>>>>>>> [ <<[->>>>>>>>>+<<<<<<<<<] >[->>>>>>>>>+<<<<<<<<<] >>>>>>>>>> ] <<[->>>+<<<] >[->>>>>+<<<<<] >> Go to memory N [->>>>+<<<<]>>>> [-[->>>>>+<<<<<]<[->>>>>+<<<<<]>>>>>>] Copy memory |N| <<[->>+<<<<<+>>>]>>[-<<+>>] Move packet back to beginning <[-<<<<<+>>>>>]<< [<<[-<<<<<+>>>>>]<[-<<<<<+>>>>>]<<] Go to memory |N| <<[->>>>>+<<<<<]<[->>>>>+<<<<<] >>>>>> [-[->>>>>+<<<<<]<[->>>>>+<<<<<]>>>>>>] Add <[->>>>+<<<<] Go back <<[<<<<<]<<<<<<[<<<<<<<<<] +<<<[->>+<<]> ]<<< o: -[>]>>[- Copy N <<<[->+>>>+<<<<]>[-<+>]>>>>>- Copy X <[-<<+>>>+<]>[-<+>] Move N and X to memory <<[->>>>>>>>>+<<<<<<<<<] >[->>>>>>>>>+<<<<<<<<<] >>>>>>>>>> [ <<[->>>>>>>>>+<<<<<<<<<] >[->>>>>>>>>+<<<<<<<<<] >>>>>>>>>> ] <<[->>>+<<<] >[->>>>>+<<<<<] >> Go to memory N [->>>>+<<<<]>>>> [-[->>>>>+<<<<<]<[->>>>>+<<<<<]>>>>>>] Copy memory N <<[->>+<<<<<+>>>]>>[-<<+>>] Move packet back to beginning <[-<<<<<+>>>>>]<< [<<[-<<<<<+>>>>>]<[-<<<<<+>>>>>]<<] Go to memory |N| <<[->>>>>+<<<<<]<[->>>>>+<<<<<] >>>>>> [-[->>>>>+<<<<<]<[->>>>>+<<<<<]>>>>>>] Set >>>[-]<<<<[->>>>+<<<<] Go back <<[<<<<<]<<<<<<[<<<<<<<<<] +<<<[->>+<<]> ]<<< r: -[>]>>[- Copy N <<<[->+>>>>>>>>>>>>>+<<<<<<<<<<<<<<]>[-<+>] >>>>>->>>>>>>>> Copy N to memory [<[->>>>>>>>>+<<<<<<<<<]>>>>>>>>>>] <[->>>>>+<<<<<]>>>>> Go to memory N [-[->>>>>+<<<<<]>>>>>] Copy memory N <[->+>+<<]>[-<+>] Copy memory N back to beginning of memory >[-<<<<<+>>>>>]<<< [<<[-<<<<<+>>>>>]<<<] <<[->>>>>+<<<<<]>>>>> Go to memory |N| [-[->>>>>+<<<<<]>>>>>]>>>>> Read >>>, Go back <[<<<<<]<<<<<<[<<<<<<<<<] +<<<[->>+<<]> ]<<< s: I hate you feel bad -[>]>>[- Copy N <<<[->+>>>+<<<<]>[-<+>]>>>>>- Move N and X to memory <<[->>>>>>>>>+<<<<<<<<<] >[->>>>>>>>>+<<<<<<<<<] >>>>>>>>>> [ <<[->>>>>>>>>+<<<<<<<<<] >[->>>>>>>>>+<<<<<<<<<] >>>>>>>>>> ] <<[->>>+<<<] >[->>>>>+<<<<<] >> Go to memory N [->>>>+<<<<]>>>> [-[->>>>>+<<<<<]<[->>>>>+<<<<<]>>>>>>] Copy memory N <<[->>+<<<<<+>>>]>>[-<<+>>] Move packet back to beginning <[-<<<<<+>>>>>]<< [<<[-<<<<<+>>>>>]<[-<<<<<+>>>>>]<<] Go to memory |N| <<[->>>>>+<<<<<]<[->>>>>+<<<<<] >>>>>> [-[->>>>>+<<<<<]<[->>>>>+<<<<<]>>>>>>] Copy memory |N| >>>[->+>>>>>+<<<<<<]>[-<+>] Move to the end <<<<<[->>>>>>>>>>>+<<<<<<<<<<<] >>>>>>>>>>>>> [<<[->>>>>+<<<<<]<[->>>>>+<<<<<]>>>>>>>>] Xor <++++++++[-[->>>+<<<]+>>>]<<<[<<<]> [->>>[->>>]+<[<<<]>] >[->>>[->>>]+<<[<<<]>>] >[>>[-<+>]>] <<<[>>>>>[-<<<++>>>]<<<+<-[>-<+[-]]<-<<<] >>>>>[-<<<<+>>>>] Bring back <<<<<<[>>[-<<<<<+>>>>>]<<<<<<<] >>[-<<<<<<<<<+>>>>>>>>>]<<<<<<<< [<[-<<<<<<<<<+>>>>>>>>>]<<<<<<<<] +<< ]<<< t: -[>]>>[- Copy N <<<[->+>>>>>>>>>>>>>+<<<<<<<<<<<<<<]>[-<+>] >>>>>->>>>>>>>> Copy N to memory [<[->>>>>>>>>+<<<<<<<<<]>>>>>>>>>>] <[->>>>>+<<<<<]>>>>> Go to memory N [-[->>>>>+<<<<<]>>>>>] Copy memory N <[->+>+<<]>[-<+>] Copy memory N back to beginning of memory >[-<<<<<+>>>>>]<<< [<<[-<<<<<+>>>>>]<<<] <<[->>>>>+<<<<<]>>>>> Go to memory |N| [-[->>>>>+<<<<<]>>>>>]>>>>> Write >>>. Go back <[<<<<<]<<<<<<[<<<<<<<<<] +<<<[->>+<<]> ]<<< [+] Copy X to next pos >>>>[->>>>>>>>>+<<<<<<<<<] Move to next op >>>>>>>>>> ]