-
Notifications
You must be signed in to change notification settings - Fork 51
/
hello_world.bf
22 lines (19 loc) · 1.17 KB
/
hello_world.bf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
>+++++++++[<++++++++>-]<.>+++++++[<++++>-]<+.+++++++..+++.>>>++++++++[<++++>-]
<.>>>++++++++++[<+++++++++>-]<---.<<<<.+++.------.--------.>>+.>++++++++++.
// Cell 0: Set to 10, loop to set Cell 1 to 80 ('H')
// Cell 1: Set to 7, loop to set Cell 2 to 101 ('e')
// Cell 2: Set to 108 ('l'), print 'l' twice, then set to 111 ('o')
// Cell 3: Set to 8, loop to set Cell 4 to 32 (space) and print it
// Cell 4: Set to 10, loop to set Cell 5 to 87 ('W') and print
// Print previous Cell 4 (space)
// Cell 5: Set to 114 ('r'), print it
// Cell 5: Set to 108 ('l'), print it
// Cell 5: Set to 100 ('d'), print it
// Print Cell 5 (new value) and Cell 6 (10 + 10 = 120)
// Print Cell 7 (ASCII 10)
Explanation of the Code:
1. Memory Cells: Brainf**k uses an array of memory cells (initialized to zero) to perform operations.
2. Data Pointer: The > and < commands move the data pointer to the right or left, respectively.
3. Increment and Decrement: The + and - commands increase or decrease the value of the current memory cell.
4. Output: The . command outputs the ASCII value of the current memory cell.
5. Looping: The [ and ] commands create loops that run while the current memory cell is not zero.