daily pastebin goal
66%
SHARE
TWEET

Brainfuck for MSP430/microcorruption / TimN

a guest Sep 26th, 2015 1,442 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Brainfuck in MSP430 assembly for https://microcorruption.com/.
  2. Go to "New Orleans" and paste in this script:
  3.  
  4. reset;
  5. let 4000 = 4031;
  6. let 4002 = fef4;
  7. let 4004 = 40b1;
  8. let 4006 = ff0;
  9. let 4008 = 8;
  10. let 400a = 40b1;
  11. let 400c = 1000;
  12. let 400e = 6;
  13. let 4010 = 4032;
  14. let 4012 = 8200;
  15. let 4014 = 12b0;
  16. let 4016 = 10;
  17. let 4018 = 4302;
  18. let 401a = 4037;
  19. let 401c = 1000;
  20. let 401e = 4035;
  21. let 4020 = 2000;
  22. let 4022 = 4036;
  23. let 4024 = 3000;
  24. let 4026 = 403f;
  25. let 4028 = 800;
  26. let 402a = 403e;
  27. let 402c = 4000;
  28. let 402e = 832e;
  29. let 4030 = 438e;
  30. let 4032 = 0;
  31. let 4034 = 831f;
  32. let 4036 = 23fb;
  33. let 4038 = 477f;
  34. let 403a = 930f;
  35. let 403c = 2450;
  36. let 403e = 903f;
  37. let 4040 = 3e;
  38. let 4042 = 2002;
  39. let 4044 = 5316;
  40. let 4046 = 3ff8;
  41. let 4048 = 903f;
  42. let 404a = 3c;
  43. let 404c = 2002;
  44. let 404e = 8316;
  45. let 4050 = 3ff3;
  46. let 4052 = 903f;
  47. let 4054 = 2b;
  48. let 4056 = 2003;
  49. let 4058 = 53d6;
  50. let 405a = 0;
  51. let 405c = 3fed;
  52. let 405e = 903f;
  53. let 4060 = 2d;
  54. let 4062 = 2003;
  55. let 4064 = 83d6;
  56. let 4066 = 0;
  57. let 4068 = 3fe7;
  58. let 406a = 903f;
  59. let 406c = 2e;
  60. let 406e = 2009;
  61. let 4070 = 466f;
  62. let 4072 = 4f81;
  63. let 4074 = 6;
  64. let 4076 = 4032;
  65. let 4078 = 8000;
  66. let 407a = 12b0;
  67. let 407c = 10;
  68. let 407e = 4302;
  69. let 4080 = 3fdb;
  70. let 4082 = 903f;
  71. let 4084 = 2c;
  72. let 4086 = 2008;
  73. let 4088 = 4032;
  74. let 408a = 8100;
  75. let 408c = 12b0;
  76. let 408e = 10;
  77. let 4090 = 4302;
  78. let 4092 = 4fc6;
  79. let 4094 = 0;
  80. let 4096 = 3fd0;
  81. let 4098 = 903f;
  82. let 409a = 5b;
  83. let 409c = 2015;
  84. let 409e = 4785;
  85. let 40a0 = 0;
  86. let 40a2 = 5325;
  87. let 40a4 = 430f;
  88. let 40a6 = 477e;
  89. let 40a8 = 930f;
  90. let 40aa = 2003;
  91. let 40ac = 903e;
  92. let 40ae = 5d;
  93. let 40b0 = 2409;
  94. let 40b2 = 903e;
  95. let 40b4 = 5b;
  96. let 40b6 = 2001;
  97. let 40b8 = 531f;
  98. let 40ba = 903e;
  99. let 40bc = 5d;
  100. let 40be = 2001;
  101. let 40c0 = 831f;
  102. let 40c2 = 3ff1;
  103. let 40c4 = 8317;
  104. let 40c6 = 3fb8;
  105. let 40c8 = 903f;
  106. let 40ca = 5d;
  107. let 40cc = 2007;
  108. let 40ce = 466f;
  109. let 40d0 = 930f;
  110. let 40d2 = 2403;
  111. let 40d4 = 4517;
  112. let 40d6 = fffe;
  113. let 40d8 = 3c01;
  114. let 40da = 8325;
  115. let 40dc = 3fad;
  116. let 40de = d032;
  117. let 40e0 = f0;
  118. let 40e2 = 3ffd;
  119. let 40e4 = 4130;
  120. let pc = 4000;
  121.  
  122. Then to run type "c".  When prompted for a program, enter a brainfuck program such as
  123.  
  124. ++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.
  125.  
  126. then type "c" to continue execution.  The CPU will halt when the program is complete.
  127.  
  128. Notes: the getchar interrupt in microcorruption didn't seem to work for me, perhaps operator error. The interpreter does attempt to getchar, but it will always receive NIL.
  129.  
  130. Source code:
  131. /*
  132.  * bf.s
  133.  *      Brainfuck for msp430/microcorruption.
  134.  *
  135.  * cpp -E bf.s > bf-cpp.s
  136.  * msp430-as -o bf.o bf-cpp.s
  137.  * msp430-ld -o bf-bin bf.o
  138.  * msp430-objdump -d bf-bin > dump
  139.  *
  140.  * TimN 2015 - Public Domain
  141.  */
  142.  
  143. #define prog 0x1000
  144. #define progsz 0x0ff0
  145. #define stackBuf 0x2000
  146. #define dataBuf 0x3000
  147. #define datasz 0x1000
  148.  
  149. #define SP      r1
  150. #define SR      r2
  151. #define STACK   r5
  152. #define PTR     r6
  153. #define PROG    r7
  154.  
  155. /* loads at 0x4000 */
  156. main:
  157.     // note: we pre-allocate room for syscall args (12 bytes)
  158.     mov #(0xff00-0xc), SP
  159.  
  160.     // gets(prog, progsz)
  161.     mov #progsz, 8(SP)
  162.     mov #prog, 6(SP)
  163.     mov #0x8200, SR
  164.     call #0x10
  165.     mov #0, SR
  166.  
  167.     // initialize interp
  168.     mov #prog, PROG
  169.     mov #stackBuf, STACK
  170.     mov #dataBuf, PTR
  171.  
  172.     // zero data[0..datasz]
  173.     mov #(datasz/2), r15
  174.     mov #(dataBuf+datasz), r14
  175. 1:  sub #2, r14
  176.     mov #0, @r14
  177.     dec r15
  178.     jne 1b
  179.  
  180. interploop:
  181.     mov.b @PROG+, r15
  182.     cmp #0, r15
  183.     jeq halt
  184.     cmp #'>', r15
  185.     jne 1f
  186.         inc PTR
  187.         jmp interploop
  188. 1:  cmp #'<', r15
  189.     jne 1f
  190.         dec PTR
  191.         jmp interploop
  192. 1:  cmp #'+', r15
  193.     jne 1f
  194.         inc.b @PTR
  195.         jmp interploop
  196. 1:  cmp #'-', r15
  197.     jne 1f
  198.         dec.b @PTR
  199.         jmp interploop
  200. 1:  cmp #'.', r15
  201.     jne 1f
  202.         // putchr(@PTR)
  203.         mov.b @PTR, r15
  204.         mov r15, 6(SP)
  205.         mov #0x8000, SR
  206.         call #0x10
  207.         mov #0, SR
  208.         jmp interploop
  209. 1:  cmp #',', r15
  210.     jne 1f
  211.         // @PTR = getchar()
  212.         // note: this doesnt seem to work in microcorruption!
  213.         mov #0x8100, SR
  214.         call #0x10
  215.         mov #0, SR
  216.         mov.b r15, @PTR
  217.         jmp interploop
  218. 1:  cmp #'[', r15
  219.     jne 1f
  220.         mov PROG, @STACK
  221.         add #2, STACK
  222.         mov #0, r15             // nesting=0
  223. while:  
  224.         mov.b @PROG+, r14       // while(nesting != 0 && cur != ']')
  225.         cmp #0, r15
  226.         jne 2f
  227.         cmp #']',r14
  228.         jeq done
  229. 2:        cmp #'[', r14         // if(cur == '[') nesting++
  230.           jne 2f
  231.             inc r15
  232. 2:        cmp #']', r14         // if(cur == ']') nesting--
  233.           jne 2f
  234.             dec r15
  235. 2:      jmp while
  236. done:  
  237.         dec PROG
  238.         jmp interploop
  239. 1:  cmp #']', r15
  240.     jne 1f
  241.         mov.b @PTR, r15
  242.         cmp #0, r15
  243.         jeq else
  244.             mov -2(STACK), PROG
  245.             jmp 1f
  246. else:      
  247.             sub #2, STACK
  248. 1:  jmp interploop
  249. halt:
  250.     bis #0xf0, SR
  251.     jmp halt
  252.     ret
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Pastebin PRO 'WINTER SPECIAL'!
Get 40% OFF Pastebin PRO accounts!
 
Top