Advertisement
Guest User

Untitled

a guest
Mar 21st, 2014
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. The following program prints "Hello World!" and a newline to the screen:
  2. +++++ +++ Set Cell #0 to 8
  3. [
  4. >++++ Add 4 to Cell #1; this will always set Cell #1 to 4
  5. [ as the cell will be cleared by the loop
  6. >++ Add 4*2 to Cell #2
  7. >+++ Add 4*3 to Cell #3
  8. >+++ Add 4*3 to Cell #4
  9. >+ Add 4 to Cell #5
  10. <<<<- Decrement the loop counter in Cell #1
  11. ] Loop till Cell #1 is zero
  12. >+ Add 1 to Cell #2
  13. >+ Add 1 to Cell #3
  14. >- Subtract 1 from Cell #4
  15. >>+ Add 1 to Cell #6
  16. [<] Move back to the first zero cell you find; this will
  17. be Cell #1 which was cleared by the previous loop
  18. <- Decrement the loop Counter in Cell #0
  19. ] Loop till Cell #0 is zero
  20.  
  21. The result of this is:
  22. Cell No : 0 1 2 3 4 5 6
  23. Contents: 0 0 72 104 88 32 8
  24. Pointer : ^
  25.  
  26. >>. Cell #2 has value 72 which is 'H'
  27. >---. Subtract 3 from Cell #3 to get 101 which is 'e'
  28. +++++ ++..+++. Likewise for 'llo' from Cell #3
  29. >>. Cell #5 is 32 for the space
  30. <-. Subtract 1 from Cell #4 for 87 to give a 'W'
  31. <. Cell #3 was set to 'o' from the end of 'Hello'
  32. +++.----- -.----- ---. Cell #3 for 'rl' and 'd'
  33. >>+. Add 1 to Cell #5 gives us an exclamation point
  34. >++. And finally a newline from Cell #6
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement