General Information
Author: Carsten Strotmann
Language: FORTH
Compiler/Interpreter: XFORTH
Published: 2003

BrainF\*ck#

BF is a very minimalistic language, with only eight commando's, yet it is (theoretically) powerfull enough to compute anything that can be computed (with a Turing Machine). The language operates on an array of memory cells each containing an initially zero integer value. There is a memory pointer which initially points to the first memory cell.

Resources#

Tom Hunt has another BF implementation for the A8 written in CC65 (see bottom of page).

a new Atari BrainFuck was written by Pawel "Cosi" Piatkowski, Announcement in Polish, download of atr with English manual and program file here.

How to use#

Each of the eigth commands consists of a single ASCII character, with the following meaning:
  • '>' : move the memory pointer to the next cell,
  • '<' : move the memory pointer to the previous cell,
  • '+' : increment the memory cell under the memory pointer,
  • '-' : decrement the memory cell under the memory pointer,
  • ',' : fills the memory cell under the memory pointer with the ASCII value of next character from the input,
  • '.' : writes the contents of the memory cell under the memory pointer as a character with the corresponding ASCII value,
  • '[' : moves to the command following the matching ']', if the memory cell under the memory pointer is zero, and
  • ']' : moves to the command following the matching '[', if the memory cell under the memory pointer is not zero.

All commands are executed sequentially, except when specified differently. Other characters are skipped, thus considered as comments. The execution terminates when the end of the program is reached.

This interpreter is written in XFORTH

Download: BrainFuck in X-FORTH/bf.atr(info)

From MyDOS, start BF.COM, then BF" D:filename.BF"

Have fun!


Source (X-FORTH)#

( Brainf*ck in FORTH      )
( 2003, Carsten Strotmann )

CR ." BrainF*ck "

0 VARIABLE IP

: IP+ IP @ 1+ IP ! ;
: IP- IP @ 1 - IP ! ;
: IP@ IP @ C@ ;

: 2DUP DUP DUP ;

: BF+ 2DUP C@ 1+ SWAP C! ;
: BF- 2DUP C@ 1 - SWAP C! ;
: BF> 1+ ;
: BF< 1 - ;
: BF. DUP C@ EMIT ;
: BF, DUP KEY SWAP C! ;
: BF[ DUP C@ 0= IF
        BEGIN IP+ IP@ 93 = UNTIL
      THEN ;
: BF] BEGIN IP- IP@ 91 = UNTIL ;

." .." 

: BFI ( addr -- )
  IP ! BEGIN
    IP@ 93 = IF BF] THEN
    IP@ 91 = IF BF[ THEN
    IP@ 62 = IF BF> THEN
    IP@ 60 = IF BF< THEN
    IP@ 46 = IF BF. THEN
    IP@ 44 = IF BF, THEN
    IP@ 45 = IF BF- THEN
    IP@ 43 = IF BF+ THEN
    IP+
    IP@ 0  = UNTIL ;

." .."

: BF 
  HERE 3000 ERASE 
  HERE 
  BL WORD 1+ BFI ;

." .."
HEX

: BFR
  6000 1000 ERASE
  7000 1000 ERASE
  BEGIN 
    6000 1000 SOURCE-ID @ READ-FILE
    128 < WHILE
    DROP 7000 6000 BFI
  REPEAT
;

." .."

: BF"
  FILE" R/O OPEN-FILE
  128 < IF
    SOURCE-ID !
    BFR
    SOURCE-ID @ CLOSE-FILE
    0 SOURCE-ID !
  ELSE
    ." Error open file"
  THEN ;

." loaded!" CR

Add new attachment

Only authorized users are allowed to upload new attachments.

List of attachments

Kind Attachment Name Size Version Date Modified Author Change note
atr
bf.atr 92.2 kB 1 20-Feb-2010 22:03 Carsten Strotmann
« This page (revision-3) was last changed on 20-Feb-2010 22:04 by Carsten Strotmann