Welcome Guest ( Log In | Register )



2 Pages V  < 1 2  
Reply to this topicStart new topic
> Brainf*ck - World's Smallest And Hardest Language
qwijibow
post Nov 4 2004, 03:56 PM
Post #11


Way Out Of Control - You need a life :)
Group Icon

Group: Members
Posts: 1,366
Joined: 14-September 04
From: Nottingham England
Member No.: 570



QUOTE(lhunath @ Nov 4 2004, 08:56 AM)
It's actually very easy and simplistic. Just takes a bit more to figure things because it's low level.
*



lol... thats what you think... you should see an IF structure in BrainF*ck !

lets say you want to compare memory address 0 to memory address 1 and if they are equal DO somthing, (Without destroying the variables, you must....

1) make a copy of the varibales to work on in memory at address 2 and 3. (so noot to change origonal variables)
to make a copy of memory address 0 to memory address 2 you need to loop through subtracting one from address zero, adding one to memory address 2 and 5(temp) on each loop... then loop through address 5 subtracting one, and addinng one to address 0 on each loop.

all of that just to make a copy of a varrable.. and you have to do that twice....

here is the brainf*ck code to copy a variable
CODE

#copy address 0 to address 1.
[->+>+<<]   #this will set address 0 to zero, but make copys in address 1 and 2.
>>[-<<+>>] #this them moves address 2 into address 0. (leaving address 2 at zero again)
now both address 0 and address one contain the origonal value of address 0


2)NEXT... you need to determine if the coppied variables are equal.
loop through coppied variable one subtracing one on each loop from itself, and coppyied variable 2.
if the variables are equal, then the body of a while next loop will not be entered from the address of coppied variable 2.....

code for "If A is not equal to B"
CODE

>>  # move to address 2
[->-<]  #subtract one from each variable untill the first variable is ZERO
>[  (THE VARIABLES ARE NOT EQUAL)  [-] ]   #the [-] sets this adress value to 0, so the loop will only run once


to make a "If A is equal to B" test, you would need to set anouther variable to one, and then enter it with a while loop... but if the NOT EQUAL code is executed, it sets the one variable to zero, preventing the while loop from being entered....

like so...
CODE

>>
[->-<]
>>+<< #set address +2 to 1 to allow the TRUE code block to run, this will be set to 0 if the  FALSE code block runs.
>[ FALSE [-]>[-]] #the [-]>[-]code zero's this loop, and the next loop, preventing the TRUE code block from running.




SO.......
In assembly, an if statement is as simple as a jump instruction, with a condition, and an address...
in BrainFu*k an if code looks like this.......

My Example of a rainF8CK IF THEN ELSE statement
CODE

,>,<
[->+>+<<]>>[-<<+>>] >
[->+>+<<]>>[-<<+>>] <
[->-<]
>>+<
[FALSE
[-]>[-] ]>
[TRUE]


and ontop of that, you have to make sure the code you insert into the TRUE and FALSE doesn not interfere with any ariables the IF THEN ELSE code uses.

i havent debuged that, its just off the top of my head, so dont be surprised if it doesnt work


Ohhh, and iif you think that looked complicated, you dont even want to know what an "IF A is bigger than B" looks like !!!!
Go to the top of the page
 
+Quote Post
cristofd
post Nov 10 2004, 10:23 PM
Post #12


Newbie [ Level 1 ]
Group Icon

Group: Members
Posts: 4
Joined: 10-November 04
Member No.: 1,339



QUOTE(musichere @ Nov 3 2004, 02:01 PM)
LOL this programming language is actually physically scary. I wish I could be as good as this.

I don't understand at all how

<snip>

can be a random number generator. More than More than More than plus plus while not zero?!
*



Someone pointed out that that's actually "move pointer 3; add 2; while (not zero) {". But understanding the semantics of the language is just the first step. If anyone wants to actually understand how the program works, the first step is to read my explanation at http://www.hevanet.com/cristofd/bf/random.txt which assumes some familiarity with the language and with cellular automata too; and the second step is to ask me questions, if it still isn't clear (and you're still interested).
Good luck;
-Daniel Cristofani.
Go to the top of the page
 
+Quote Post
cristofd
post Nov 10 2004, 10:38 PM
Post #13


Newbie [ Level 1 ]
Group Icon

Group: Members
Posts: 4
Joined: 10-November 04
Member No.: 1,339



QUOTE(qwijibow @ Nov 4 2004, 07:56 AM)
lets say you want to compare memory address 0 to memory address 1 and if they are equal DO somthing, (Without destroying the variables, you must....

1) make a copy of the varibales to work on in memory at address 2 and 3. (so noot to change origonal variables)
*



Not entirely necessary. Here's another approach:

CODE

,>,[<->>+<-]
[a-b 0 b 0 0]

+<[ A!=B >->>]>[ A==B ->>>]
[a-b 0 b 0 0]

<<[<<+>+>-]
[a b 0 0 0]


-Daniel.
Go to the top of the page
 
+Quote Post
qwijibow
post Nov 10 2004, 11:27 PM
Post #14


Way Out Of Control - You need a life :)
Group Icon

Group: Members
Posts: 1,366
Joined: 14-September 04
From: Nottingham England
Member No.: 570



your code makes no sence to me....

CODE
[a-b 0 b 0 0]


this executes straigth after a closed loop... the the contents of the memory will alsways equal zero, so this loop is never entered.. and if it was entered, it would just loop round subtracting one untill it was at zero...

Go to the top of the page
 
+Quote Post
cristofd
post Nov 11 2004, 04:30 AM
Post #15


Newbie [ Level 1 ]
Group Icon

Group: Members
Posts: 4
Joined: 10-November 04
Member No.: 1,339



QUOTE(qwijibow @ Nov 10 2004, 03:27 PM)
this executes straigth after a closed loop... the the contents of the memory will alsways equal zero, so this loop is never entered..
*



Exactly. That part is a comment. The actual working code is these three lines:

CODE

,>,[<->>+<-]
+<[ A!=B >->>]>[ A==B ->>>]
<<[<<+>+>-]


and then to explain what it was doing I added comments which are a map of the memory, so for instance when I wrote

CODE

,>,[<->>+<-]
a-b 0 b 0 0


I meant that after this line of code is done executing, the first cell has (A minus B), the second cell has a zero, the third cell has B, and the fourth and fifth cells have zeroes.

Then, to prevent the "-" in the comments from being executed as a brain**** command, I put the comments in loops that would never be executed, because the cell was known to be zero. Maybe I should have explained that to begin with?

-Daniel.
Go to the top of the page
 
+Quote Post
qwijibow
post Nov 11 2004, 01:26 PM
Post #16


Way Out Of Control - You need a life :)
Group Icon

Group: Members
Posts: 1,366
Joined: 14-September 04
From: Nottingham England
Member No.: 570



Ahhh.. okay i understand...
for simplicity, i just make sure not to use BF code in comments..

i use SUB for '-' and ADD for '+'.

great language though !

makes me want to attempt to learn assembly.... again !
Go to the top of the page
 
+Quote Post
Darren
post Nov 18 2004, 10:36 AM
Post #17


Premium Member
Group Icon

Group: Members
Posts: 205
Joined: 8-September 04
From: Vic, Australia
Member No.: 394



This language is very complicated considering the minimal amount of commands. I greatly admire anyone who takes the time to use it on complex programs. Even simple programs for that matter. Are there many games written in it? Does anyone know where i try some out?
Go to the top of the page
 
+Quote Post
cristofd
post Nov 19 2004, 10:32 AM
Post #18


Newbie [ Level 1 ]
Group Icon

Group: Members
Posts: 4
Joined: 10-November 04
Member No.: 1,339



QUOTE(Darren @ Nov 18 2004, 02:36 AM)
This language is very complicated considering the minimal amount of commands. I greatly admire anyone who takes the time to use it on complex programs. Even simple programs for that matter. Are there many games written in it? Does anyone know where i try some out?
*



No games yet. Probably the closest thing is the cellular automaton "life", here:
http://www.df.lth.se/~lft/brain****/

Tic-tac-toe and guess-a-number are on my to-do list, but they've been there a while.

The best general source for brain**** source code is the repository at:
http://esoteric.sange.fi/brain****/

(Fix censoring in both URLs.)

Good luck;
-Daniel Cristofani.
Go to the top of the page
 
+Quote Post
DrK3055A
post Oct 22 2006, 12:44 AM
Post #19


Member [ Level 1 ]
Group Icon

Group: Members
Posts: 46
Joined: 18-October 06
Member No.: 16,664



QUOTE(cristofd @ Nov 19 2004, 12:32 PM) *

No games yet. Probably the closest thing is the cellular automaton "life", here:
http://www.df.lth.se/~lft/brain****/

Tic-tac-toe and guess-a-number are on my to-do list, but they've been there a while.

The best general source for brain**** source code is the repository at:
http://esoteric.sange.fi/brain****/

(Fix censoring in both URLs.)

Good luck;
-Daniel Cristofani.


Here is my version of a BrainF*ck compiler for DOS, 114 byte sized:

CODE


                 MOV AH,9h
                 MOV DX,EMPEZAR
                 INT 021h
LEER:
                 MOV AH,8h
                 INT 021h
                 MOV DI,BFLOOP
AUN_NO:          DEC DI
                 CMP B[DI],AL
                 JE IMPRIME
                 CMP B[DI],CH
                 JNE AUN_NO
                 JMP LEER+2
IMPRIME:         MOV DX,DI
                 INC DX
                 PUSH AX
                 MOV AH,9h
                 INT 021h
                 POP AX
                 CMP AL,040h
                 JNE LEER
                 RET

EMPEZAR:         MOV BH,80h
                 MOV CX,BX
                 MOV DI,BX
                 REP STOSB
                 DB '$',0

                 DB '>'
                 INC BX
                 DB '$'
        
                 DB '<'
                 DEC BX
                 DB '$'

                 DB '+'
                 INC B[BX]
                 DB '$'

                 DB '-'
                 DEC B[BX]
                 DB '$'

                 DB '.'
                 MOV AH,2
                 MOV DL,B[BX]
                 INT 021h
                 DB '$'

                 DB ','
                 MOV AH,8
                 INT 021h
                 MOV B[BX],AL
                 DB '$'

                 DB '@'
                 INT 20h

                 DB ']'
                 RET
                 DB '$'

                 DB '['
BFLOOP:          CALL AQUI
AQUI:
                 POP SI
                 SUB SI,3h
                 PUSH SI
                 OR B[BX],CH
                 JNE FUERA
                 POP AX
BUCLE:           LODSB
                 CMP AL,0E8h
                 JNE OTRO
                 INC CX
OTRO:            CMP AL,0C3h
                 JNE BUCLE
                 LOOP BUCLE
                 JMP SI
FUERA:           DB '$'



For those who don't want to assemble this compiler of BF, here is the uuencoded version of the COM executable:

CODE

begin 644 bf.com
MM`FZ)P'-(;0(S2&_5@%/.`5T!C@M=??K\(GZ0E"T"<TA6#Q`=>'#MX"+RXG?
M\ZHD`#Y#)#Q+)"O^!R0M_@\D+K0"BA?-(20LM`C-(8@')$#-(%W#)%OH``!>
8@^X#5@@O=0]8K#SH=0%!/,-U]N+T_^8D
`
end



You use this compiler to generate .COM executables from BF source code. The source code must not have any character other than BF commands, and the BF program must end with the "@" character flag. For example, the random number generator above mentioned:

CODE

>>>++[
<++++++++[
<[<++>-]>>[>>]+>>+[
-[->>+<<<[<[<<]<+>]>[>[>>]]]
<[>>[-]]>[>[-<<]>[<+<]]+<<
]<[>+<-]>>-
]<.[-]>>
]@


Then you use the compiler by writing this command line:

BF <RANDOM.BF >RANDOM.COM

And then you run RANDOM.COM to watch the result...

If you need to clean up the code, you can use my BF sourcecode cleaner (CLEAN.BF):

CODE

+[>,[>+>>+<<<-]++++++++[>--------<-]>[<<+>><+++[>+++++++<-]+>[<->[
->+<]]<[>>>.<<<-]+>>--[<<->>[-<+>]]<<[>>>.<<<-]+>+[<->[->+<]]<[>>>
.<<<-]+>>--[<<->>[-<+>]]<<[>>>.<<<-]+>>+++++++[<-->-]<[<->[->+<]]<
[>>>.<<<-]+>>--[<<->>[-<+>]]<<[>>>.<<<-]+>>+++++++[<---->-]<-[<->[
->+<]]<[>>>.<<<-]+>>--[<<->>[-<+>]]<<[>>>.<<<-]>[-]]>>[-]<<<<-]>++
++++++[<++++++++>-]<.@


Then you compile CLEAN.BF into CLEAN.com:

BF <CLEAN.BF >CLEAN.COM

And then, to compile any commented BF program:

CLEAN <program.bf | BF >program.com

Try out this code:

CODE
+[->,.-------------]<[++++++++++++++.<]@


This is my Hello World in BF:

CODE

>+++++++++[<++++++++>-]<.>+++++[<++++++++>-]<-.---.>+++[<---->-]<+.[-]>+++++[<++++++>-]<++.>++++++[<+++++++>-]<+++.>+++++[<++++++++>-]<.-------.+>>>+++++[<+++++[<++++>-]>-]<<.<.>>>+++++[<++++++>-]<+++.-.<<++++.----.++++++++++.>>.<[-]>[<++>-]+++[<++++>-]<+.[-]++++[<------>-]<.>++++[<++++>-]<+.---------.++++++.[-]>++++++++[<++++++>-]<--.@


I've attached a BF debugger of my creation for debugging these BF programs (so you will understand quickly their operation.
Attached File(s)
Attached File  BrainFuck_Debugger.zip ( 5.06k ) Number of downloads: 10
 
Go to the top of the page
 
+Quote Post

2 Pages V  < 1 2
Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. War Of The Worlds(4)
  2. What Is: World's Largest Known Prime Number(20)
  3. World's Longest Single Word Domain Name!(76)
  4. World's Samllest Real OS(15)
  5. Worlds Oldest Search Engine....(17)
  6. Worlds Largest Search Engine Directory(10)
  7. World's Smallest Website(71)
  8. Smallest Portable Pc Is Incredible(4)
  9. World's First 3d Display Revealed(12)
  10. Smallest Webserver(14)
  11. Player Worlds Guide(0)
  12. Which Is The Smallest Game Imaginable?(4)
  13. World's Costliest Phone Earn A Guiness Record(15)
  14. Copernic Agent(6)
  15. Rfid4u Brings World's Largest Rfid Elearning Portal Teamrfid.com(0)
  1. Worlds Smallest Tech Products....., Umight Not Beleive What U See Here(16)


 



- Lo-Fi Version Time is now: 8th September 2008 - 02:57 AM