Advertisement
imk0tter

BrainFuck: Integer Display

Apr 6th, 2011
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. v1
  2. v1
  3. buff
  4. v2
  5. v2
  6. buff
  7. blank
  8. 1
  9. blank
  10. v1c
  11. v2c
  12. blank
  13. divbuff
  14. basebuff
  15. baseflag
  16. basebuffr
  17. basebuffr2
  18. v1neg
  19. r1
  20. r2
  21. r3
  22. r4
  23. r5
  24. r6
  25. 1
  26. 1
  27. 1
  28. {ref}
  29. 6
  30.  
  31.  
  32. push input into cell 0
  33. ,  
  34.            
  35. copy from cell 0 into cell 1 and 2 then move from 2 to 0
  36. [->+>+<<]>>[<<+>>-]>
  37.  
  38. push 10 into cell 3
  39. ++++++++++
  40.  
  41. push 10 into cell 4 and 5
  42. [>++++++++++[>++++++++++
  43.  
  44. push 10 into cell 6 and 7 and multiply giving 100000 in cell 7
  45. [>++++++++++[>++++++++++<-]<-]<-]<-]
  46.  
  47. move data from cell 7 into cell 3
  48. >>>>[<<<<+>>>>-]
  49.  
  50. point to cell 3
  51. <<<<
  52.  
  53. copy data from cell 3 to 4 and 5 then move from 5 to 3 
  54. [->+>+<<]>>[<<+>>-]
  55.  
  56. reserve variable space
  57. >>+>>>>>>>>>>
  58.  
  59. fill cell 20 through 26 with 1s and reserve a 0 at cell 27 for {ref}
  60. >>>+>+>+>+>+>+>+>>
  61.  
  62. push 6 into cell 28 which represents the current power iteration
  63. ++++++
  64.  
  65. start main loop                                    
  66. [
  67.     point to cell 14 and set cell 14 aka baseflag to 1
  68.     <<<<<<<<<<<<<<[-]+
  69.    
  70.     start position loop
  71.     [
  72.  
  73.         point to cell 1 aka v1{2}
  74.         <<<<<<<<<<<<<
  75.  
  76.         copy v1{2} to cell 9 aka v1c
  77.         [->>>>>>>>+<<<<<<<<]
  78.        
  79.         point to cell 4 aka v2{2}
  80.         >>>
  81.        
  82.         copy from v2{2} to cell 10 aka v2c
  83.         [->>>>>>+<<<<<<]
  84.        
  85.         copy v2{1} to v2{2} and cell 5 then move from cell 5 to v2{1}
  86.         <[->+>+<<]>>[<<+>>-]
  87.        
  88.         point to cell 9
  89.         >>>>
  90.        
  91.         if v1c is nonzero enter loop
  92.         [
  93.             if both v1c and v2c are nonzero subtract 1 from v1c and v2c and add 1
  94.             to cell 12 then move then point to cell 11
  95.             >[-<->>>+<]
  96.        
  97.        
  98.             move the pointer back one cell pointing to cell 9 if cell 10 was nonzero
  99.             and pointing to cell 8 otherwise       
  100.             <<
  101.         ]
  102.        
  103.  
  104.         move the pointer back one cell and look for a 1 signaling that the pointer
  105.         is in cell 7 rather than 8 and if so move it ahead to 8 to resynch     
  106.         <[>]                           
  107.                                
  108.         move what's left from v1c to v1{2}                     
  109.         >[-<<<<<<<<+>>>>>>>>]
  110.        
  111.         clear v2c
  112.         >[-]
  113.        
  114.         add 1 to cell 13 aka basebuff which represents the current position tally
  115.         then point to divvbuff
  116.         >>>+<
  117.        
  118.         subtract divbuff from v2{2}
  119.         [-<<<<<<<<->>>>>>>>]
  120.        
  121.         point to divbuff
  122.         <<<<<<<<
  123.        
  124.         if v2{2} isn't empty subtract 1 from basebuff and clear v2{2} and set baseflag to 0
  125.         [[-]>>>>>>>>>->-<<<<<<<<<<]
  126.        
  127.         copy v2{1} to v2{2}                            
  128.         <[->+>+<<]>>[<<+>>-]
  129.        
  130.         if base flag is 0 end loop
  131.         >>>>>>>>>
  132.        
  133.         end position loop
  134.     ]
  135.    
  136.     move basebuff to cell 15 aka basebuffr and cell 16 aka basebuffr2
  137.     <[->>+>+<<<]>>
  138.    
  139.     add 1 to basebuffr
  140.     +
  141.    
  142.    
  143.     [
  144.         subtract 1 from basebuffr and point to cell 26
  145.         ->>>>>>>>>>>
  146.    
  147.         from cell 26 search back to the first empty memory cell which would be
  148.         cell 19 aka r2 on the first iteration and then add 1 to the cell behind it
  149.         being r1 on the first iteration
  150.         [<]<+
  151.    
  152.         move 2 cells ahead of r1 on the first iteration and search ahead to the
  153.         first empty cell which will be cell 27 aka {ref} and then point back to
  154.         cell 15 aka basebuffr
  155.         >>[>]<<<<<<<<<<<<
  156.     ]  
  157.                                        
  158.     point back to cell 26 and search back to find the first empty memory cell
  159.     being r2 on the first iteration and empty the cell infront of it
  160.     >>>>>>>>>>>[<]>[-]
  161.    
  162.     point to the cell ahead of the recently emptied cell and search forward
  163.     for the next empty cell which would be {ref}
  164.     >[>]
  165.    
  166.     point to cell 16 aka basebuffr2
  167.     <<<<<<<<<<<
  168.    
  169.     [
  170.         if cell 16 isn't empty then move to v2{2} and clear it
  171.         -<<<<<<<<<<<<[-]
  172.    
  173.         copy v2{1} to v2{2} and point to v2{2}
  174.         <[->+>+<<]>>[<<+>>-]<
  175.    
  176.         add the contents of v2{2} to cell 17 aka v1neg
  177.         [->>>>>>>>>>>>>+<<<<<<<<<<<<<]
  178.    
  179.         repeat until basebuffr2 is empty
  180.         >>>>>>>>>>>>
  181.        
  182.         end loop and point to cell 17
  183.     ]>
  184.    
  185.     subtract v1neg from v1{1}
  186.     [-<<<<<<<<<<<<<<<<<->>>>>>>>>>>>>>>>>]
  187.    
  188.     clear v1{2}
  189.     <<<<<<<<<<<<<<<<[-]
  190.    
  191.     copy v1{1} to v1{2}
  192.     <[->+>+<<]>>[<<+>>-]>>
  193.    
  194.     subtract 1 from v2{1}
  195.     <-
  196.    
  197.     if v2{1} isn't empty then start the loop
  198.     [
  199.    
  200.         add 1 back to v2{2} and divide it by 10
  201.         +>[-]<[>>++++++++++[-<<->>]<+<]
  202.     ]
  203.    
  204.     copy v2{1} to v2{2}
  205.     >[->+<<+>]>[-<+>]
  206.    
  207.     subtract 1 from cell 28
  208.     >>>>>>>>>>>>>>>>>>>>>>>-
  209. ]
  210.  
  211. point to cell 16 and empty
  212. <<<<<<<<<<<<[-]
  213.  
  214. multiply 6 by 8 into cell 17 and subtract by 1
  215. ++++++[->++++++++<]>-
  216.  
  217. add 47 to r1 through r6
  218. [->+>+>+>+>+>+<<<<<<]
  219.  
  220. print r1 through r6
  221. >.>.>.>.>.>.
  222.  
  223. clear all variables and point back to cell 0
  224. [-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement