flat assembler
Message board for the users of flat assembler.

Index > Heap > BrainF***

Author
Thread Post new topic Reply to topic
THEWizardGenius



Joined: 14 Jan 2005
Posts: 382
Location: California, USA
THEWizardGenius
I have created a tool that may or may not be helpful for creating BrainF*** programs.
For those of you who don't know what BrainF*** is, it's a minimalist esoteric programming language. It has only 8 instructions, yet is Turing complete.
(Yes, it does have a bad word in its name, which in order to keep this board clean, I have asterix'd out)
Most BrainF*** interpreters or compilers (yes, it can be compiled to machine language too) provide an array of 30,000 cells; cell size is implementation-specific, although it is usually an unsigned byte (sometimes it is a signed byte, a 16- or 32-bit word, or any number of other things). You can manipulate one cell at a time, with "+" or "-", and change which cell you are currently working in with "<" or ">".
Code:
     +     Increment the contents of the current data cell
     -      Decrement the contents of the current data cell
     <     Decrement the data pointer
     >     Increment the data pointer
     [      Begin a WHILE loop (WHILE current data cell is nonzero)
     ]      End a WHILE loop (jump to "[" if current data cell is nonzero)
     .      Display the current cell MOD 256 as an ASCII char
     ,      Input a single character from the keyboard and store its ASCII
            value at the current data cell. Waits for the key to be pressed.
    

With these 8 instructions, BF can solve any problem that is solvable, theoretically- though for some problems, it might take a while, etc.
In BF have been written all the standard test programs- 99 Bottles of Beer, "Hello, World!", programs that echo their input to their output, and yes, even quines (programs which display their own sourcecode on the screen).
Many tools have been provided for free by "avid" BrainF*** fans and programmers. There is even a program called "BrainF*** Developer" or something like that which interprets BF code (albeit slowly) and can single-step through code. It shows the current memory contents as well.
However, as you can imagine, programming in BF can be long and tedious, even with the best tools. To add 10 to the current cell, you have to type "++++++++++". For small numbers, this is OK, but for large numbers it isn't.

So for those of you who like BrainF*** or would like to learn, I have created a tool called the BrainF*** preprocessor. I provide the sourcecode, the binary, and a readme file documenting everything. The source code is in QBasic (sorry) because I don't know much about how real preprocessors work, so I invented my own way to do it. My preprocessor takes simple commands and valid BrainF*** code and spits out only valid BrainF*** code. For example,
Code:
+10
    

is spit out as
Code:
'Add 10
++++++++++
    

(Notice that it includes a comment to make debugging of the output file much easier).
It has many useful features, which you might like. Now you can write BrainF*** programs much more easily. It also gives the option of stripping all comments from the output file (a comment is a line which begins with
the ' character) afterwards. My tool is easy to use, and can be extended or whatever. I'll probably add more things in the future. It only works in DOS, or in a Windows DOS box. With the sourcecode and also the readme file (which gives information about implementing a BFP-compatible interpreter, compiler, or preprocessor) one could probably make something similar to and compatible with BFP, possibly in another language or for another OS (such as Windows or Linux). BFP is in a ZIP archive; if you don't have Windows XP, WinZip, or something similar, tell me and I'll send you the files individually.
BTW, in the files included you'll see HTCP often. HTCP stands for "High Text Computer Programming" which is a small group of Open Source programmers.

For those of you who think BrainF*** is useless, it isn't. It can do a lot, and it may be worth your time to check out something called EsoAPI, which is used to extend esoteric languages without changing the way they function.
The website where you can learn about EsoAPI (and BOS, a BrainF*** OS, and EsoOS, an esoteric operating system) is www.kidsquid.com - it has lots of useful, cool, and interesting things. With BFP, EsoAPI, BrainF*** developer, and other things, BrainF*** can become useful. Even if not, it's fun to program in as a hobby, or to show off your skills. Cool

BrainF*** will probably be a key part of my OS in the early development stages, because I'm not good enough to write a full-blown compiler for an HLL. Laughing


Description: This is the BrainF*** Preprocessor, along with sourcecode and readme file. The files in the .ZIP archive are bfp.bas (source code), bfp.exe (executable), and bfp.txt (readme). Check it out!
Download
Filename: BFP.zip
Filesize: 41.74 KB
Downloaded: 434 Time(s)


_________________
FASM Rules!
OS Dev is fun!
Pepsi tastes nasty!
Some ants toot!
It's over!
Post 23 Jun 2005, 22:13
View user's profile Send private message AIM Address Reply with quote
THEWizardGenius



Joined: 14 Jan 2005
Posts: 382
Location: California, USA
THEWizardGenius
There seems to be a mistake with the string compiling functions and possibly with the string display function. I will have to fix this. In the mean time, I've been writing some stuff just for fun- interpreters for Hello and HQ9++, and a program that converts BrainF*** code to Ook Ook code. Hello, HQ9++, and Ook Ook are joke languages. I plan to upload them tomorrow (I'm at school and don't have them on a disk).
Post 27 Jun 2005, 01:19
View user's profile Send private message AIM Address Reply with quote
Chewy509



Joined: 19 Jun 2003
Posts: 297
Location: Bris-vegas, Australia
Chewy509
Can you do one for COW? http://www.bigzaphod.org/cow/

OOO Moo Moo OOO MOo mOO
Post 27 Jun 2005, 02:53
View user's profile Send private message Visit poster's website Reply with quote
vbVeryBeginner



Joined: 15 Aug 2004
Posts: 884
Location: \\world\asia\malaysia
vbVeryBeginner
the cow is nice,
but the sound is owful :-p

btw, this language is really interesting,
i open another view of programming language
Post 27 Jun 2005, 05:02
View user's profile Send private message Visit poster's website Reply with quote
vbVeryBeginner



Joined: 15 Aug 2004
Posts: 884
Location: \\world\asia\malaysia
vbVeryBeginner
i just wonder, why we need to use

mov eax,5
?

why can't just
eax 5 <- move value 5 into eax
[5] eax <- move value of eax into memory address 5
eax+ <- increase eax by 1
eax- <- decrease eax by 1
eax?ebx <- compare eax with ebx
jl eax, jh eax, je eax
@< <- jump to previous @:
>@ <- jump to next @:


for me, i preffer simple,
4 characters are more easier to manage than 10 characters :p
Post 27 Jun 2005, 05:25
View user's profile Send private message Visit poster's website Reply with quote
THEWizardGenius



Joined: 14 Jan 2005
Posts: 382
Location: California, USA
THEWizardGenius
You thinking of inventing a new style of assembly language?
You might want to look at http://www.terse.com/ which is the website for Terse. Terse is assembly, but with different syntax. For example, what in Intel-style assembly looks like
Code:
add ax, bx
    

Looks like this in Terse:
Code:
ax+bx
    

The code
Code:
int 10h
    

Looks like this in Terse:
Code:
!10
    

I like Terse, but it ain't free. I may write a free program to convert Terse to normal Intel-style assembly that can be compiled with FASM, because Terse is pretty cool. Of course, Terse is probably copywronged, patented, etc., so it will not be quite the same as Terse.

_________________
FASM Rules!
OS Dev is fun!
Pepsi tastes nasty!
Some ants toot!
It's over!
Post 27 Jun 2005, 23:10
View user's profile Send private message AIM Address Reply with quote
THEWizardGenius



Joined: 14 Jan 2005
Posts: 382
Location: California, USA
THEWizardGenius
I might write one for COW, perhaps even with the DDX extensions. I am currently working with Ook! (another very important language) and the BrainF*** Preprocessor (BFP) which is so far not yet working.
Post 28 Jun 2005, 00:03
View user's profile Send private message AIM Address Reply with quote
Chewy509



Joined: 19 Jun 2003
Posts: 297
Location: Bris-vegas, Australia
Chewy509
THEWizardGenius wrote:
I might write one for COW, perhaps even with the DDX extensions.

I hope you realise I was joking? Confused
Post 28 Jun 2005, 00:30
View user's profile Send private message Visit poster's website Reply with quote
crc



Joined: 21 Jun 2003
Posts: 637
Location: Penndel, PA [USA]
crc
<sigh> I was bored so I wrote a BrainF*** interpreter in RetroForth. The code follows:

Code:
loc:
variable count variable loop
create bf 'b 1, 'f 1, 0 1,
: setFunction bf 2 + c! bf 3 ;
: bfHandler setFunction find ?if execute ;; then 2drop ;
: bfReset here 1000 0 fill ;
: bfi bfReset here -rot repeat count ! dup c@ bfHandler 1+ count @ 0; 1- again ;
here ] lnparse bfi drop h0 ! ;
here ] dup loop ! ;
here ] here @ 0 =if count @ 1- count ! ;; then loop @ 2dup - count @ + count ! nip ;
;loc alias bf] alias bf[ alias bfi

: bf> 4 allot ;
: bf< -4 allot ;
: bf+ here @ 1+ here ! ;
: bf- here @ 1- here ! ;
: bf. here @ . ;
: bf, key here ! ;

| A test...
bfi +++++a[.-].     


I might bother to translate this to assembly one day. Or maybe not Smile
Post 28 Jun 2005, 01:09
View user's profile Send private message Visit poster's website Reply with quote
THEWizardGenius



Joined: 14 Jan 2005
Posts: 382
Location: California, USA
THEWizardGenius
Of course I realized you were joking!

Thanks for the code crc, you don't need to translate it to assembly. Did you know there have been BF interpreters written in BF?

_________________
FASM Rules!
OS Dev is fun!
Pepsi tastes nasty!
Some ants toot!
It's over!
Post 28 Jun 2005, 01:37
View user's profile Send private message AIM Address Reply with quote
vbVeryBeginner



Joined: 15 Aug 2004
Posts: 884
Location: \\world\asia\malaysia
vbVeryBeginner
i would preffer
i.10 <- for calling interrupt 10h

@: <- anonymous address locator ( for near jump)

->proc1 <- jump to proc1 (push thingy into stack)
>proc1 <- jump to proc1 (no push thingy into stack) normal jump

proc1: <- procedure start

:proc1 <- procedure end
Post 28 Jun 2005, 01:38
View user's profile Send private message Visit poster's website Reply with quote
THEWizardGenius



Joined: 14 Jan 2005
Posts: 382
Location: California, USA
THEWizardGenius
OK, Here it is... HTCP JokeLangs pack v1.0!
Check out readme.txt, then jokelang.txt. Be sure to try everything out. I even included specifications for all the languages, so you can read them yourself! jokelang.txt has language reference, examples, etc. I added a couple instructions to the Hello and HQ9++ which are not part of the original language specs, for debugging. Now you can debug your HQ9++ programs!


Description: Here it is. JokeLangs pack v1.0. Check it out. And remember, I'll expand and update!
Download
Filename: JOKELANG.zip
Filesize: 117.64 KB
Downloaded: 432 Time(s)


_________________
FASM Rules!
OS Dev is fun!
Pepsi tastes nasty!
Some ants toot!
It's over!
Post 01 Jul 2005, 18:18
View user's profile Send private message AIM Address Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.