Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.34 KB | None | 0 0
  1. architecture yafn {
  2. registers:
  3. storage sys_reg[96];
  4.  
  5. view ssz = sys_reg[0..32]; /* stack size */
  6. view spn = sys_reg[32..64]; /* pointer to stack's beginning */
  7. view err = sys_reg[64..96]; /* error register */
  8.  
  9.  
  10. memory:
  11. /* 0xFFFFFFFF because we use 32-bit integers, so it will just fit */
  12. range __constants [0x0..0xFFFFFFFF] {
  13. cell = 8;
  14. endianess = little-endian;
  15. granularity = 0;
  16. }
  17.  
  18. range __data [0x0..0xFFFFFFFF] {
  19. cell = 8;
  20. endianess = little-endian;
  21. granularity = 0;
  22. }
  23.  
  24. range __stack [0x0..0xFFFFFFFF] {
  25. cell = 8;
  26. endianess = little-endian;
  27. granularity = 0;
  28. }
  29.  
  30.  
  31. range __code [0x0..0xFFFFFFFF] {
  32. cell = 8;
  33. endianess = little-endian;
  34. granularity = 0;
  35. }
  36.  
  37. instructions: /* encodings */
  38. encode __dat field = immediate[32] data; /* some integer */
  39. encode __off field = immediate[32] offset; /* offset in memory */
  40. encode __lbl field = immediate[32] offset; /* pointer to instruction */
  41.  
  42. encode __reg field = register {
  43. ssz = 00,
  44. spn = 01,
  45. err = 10
  46. };
  47.  
  48.  
  49. instructions: /* base */
  50. instruction emp = { 0000 0000 }; /* do nothing */
  51. instruction hlt = { 0000 0001 }; /* exits program */
  52. instruction brp = { 0000 0010 }; /* breakpoint */
  53. instruction wrt = { 0000 0011 }; /* outouts int from stack to console */
  54. instruction srt = { 0000 0100 }; /* sorts last N elements of stack */
  55.  
  56.  
  57. instructions: /* stack instructions */
  58.  
  59. instruction epush = { 0001 0001 }; /* pushes error register to stack */
  60.  
  61. instruction ipush = { 0001 0010, __dat as dat }; /* pushes integer to stack */
  62. instruction mpush = { 0001 0011, __off as off }; /* pushes from mem storage to stack */
  63. instruction cpush = { 0001 0100, __off as off }; /* pushes from constants storage to stack */
  64.  
  65. /* pop instructions */
  66. instruction pop = { 0001 0101 }; /* discards top value from stack */
  67. instruction dpl = { 0001 0110 }; /* duplicates last element from stack */
  68. instruction sav = { 0001 0111, __off as off }; /* pops data from stack and stores it in memory */
  69. instruction swp = { 0001 1000 }; /* swaps top two values */
  70. instruction svs = { 0001 1001 }; /* pops data and place in memory to save */
  71.  
  72. instruction rnd = { 0001 1010 }; /* pushes to stack random int */
  73.  
  74. instruction smpsh = { 0001 1011 }; /* gets mem_ptr from stack to push fom mem */
  75. instruction scpsh = { 0001 1100 }; /* gets const_ptr from stack to push fom mem */
  76.  
  77.  
  78. /* all operations automatically pops top elements, so it's necessary to use `dpl` */
  79. instructions: /* arithmetics */
  80. instruction add = { 0010 0000 }; /* adds two top values on stack */
  81. instruction sub = { 0010 0001 }; /* substracts two top values of stack */
  82. instruction mul = { 0010 0010 }; /* multiplies two top values of stack */
  83. instruction div = { 0010 0011 }; /* dividies two top values of stack and pushes to
  84. stack result integer division and remainder */
  85. instruction neg = { 0010 0100 }; /* negatives top element of stack */
  86.  
  87. instruction inc = { 0010 0101 }; /* increments top element of stack */
  88. instruction dec = { 0010 0110 }; /* decrements top element of stack */
  89.  
  90.  
  91. instructions: /* bitwise ops */
  92. instruction bor = { 0011 0000 }; /* bitwise or */
  93.  
  94. instruction band = { 0011 0001 }; /* bitwise and */
  95.  
  96. instruction and1 = { 0011 0100 }; /* bitwise and of top element and 1 */
  97. instruction and2 = { 0011 0101 }; /* bitwise and of top element and 2 */
  98. instruction and3 = { 0011 0110 }; /* bitwise and of top element and 4 */
  99. instruction and4 = { 0011 0111 }; /* bitwise and of top element and 8 */
  100.  
  101. instruction lsh = { 0011 0010 }; /* left shift */
  102. instruction lsh1 = { 0011 1000 }; /* shifts top element left on 1 */
  103. instruction lsh2 = { 0011 1001 }; /* shifts top element left on 2 */
  104.  
  105. instruction rsh = { 0011 0011 }; /* right shift */
  106. instruction rsh1 = { 0011 1100 }; /* shifts top element right on 1 */
  107. instruction rsh2 = { 0011 1101 }; /* shifts top element right on 2 */
  108.  
  109. instruction bxor = { 0011 1111 }; /* bitwise xor */
  110.  
  111. instructions: /* conditions and jumps */
  112. instruction cmp = { 0100 0000 }; /* compares two elements
  113.  
  114. ---------------------
  115. | state | pushes |
  116. ---------------------
  117. | == | 001 |
  118. | >= | 011 |
  119. | <= | 101 |
  120. | > | 010 |
  121. | < | 100 |
  122. ---------------------
  123.  
  124. So, the first bit for equality,
  125. second one for greatness and
  126. third one for less */
  127.  
  128. instruction eq = { 0100 0001 }; /* pushes 1 if top values equal, else 0 */
  129. instruction jmp = { 0100 0100, __lbl as lbl }; /* jumps to instruction */
  130. instruction jez = { 0100 0101, __lbl as lbl }; /* jmps to instructions if 0 on stack top */
  131. instruction jnz = { 0100 0110, __lbl as lbl }; /* jmps to instructions if on stack top not 0 */
  132. instruction call = { 0100 0111, __lbl as lbl }; /* jmps to instructions and pushes current cursor to stack */
  133.  
  134. instruction ret = { 0100 1000 }; /* jps to address at stack top and pops */
  135. instruction cmp0 = { 0100 1001 }; /* compares with 0 */
  136.  
  137.  
  138. mnemonics: /* formats */
  139. format plain1 is "{1}"; /* for numbers */
  140. format mem_ptr is "*{1}"; /* for memory pointers */
  141. format const_ptr is "#{1}"; /* for constants pointers */
  142.  
  143. mnemonics: /* base */
  144. mnemonic emp();
  145. mnemonic hlt();
  146. mnemonic brp();
  147. mnemonic wrt();
  148. mnemonic srt();
  149.  
  150. mnemonics: /* stack instructions */
  151. mnemonic epush();
  152.  
  153. mnemonic push for ipush(dat) plain1;
  154. mnemonic push for cpush(off) const_ptr;
  155. mnemonic push for mpush(off) mem_ptr;
  156.  
  157. mnemonic pop();
  158. mnemonic dpl();
  159. mnemonic sav for sav(off) mem_ptr;
  160. mnemonic swp();
  161. mnemonic sav for svs();
  162.  
  163. mnemonic rnd();
  164.  
  165. mnemonic smpsh();
  166. mnemonic scpsh();
  167.  
  168.  
  169. mnemonics: /* arithmetics instructions */
  170. mnemonic add();
  171. mnemonic sub();
  172. mnemonic mul();
  173. mnemonic div();
  174.  
  175. mnemonic neg();
  176.  
  177. mnemonic inc();
  178. mnemonic dec();
  179.  
  180.  
  181. mnemonics: /* bitwise instructions */
  182. mnemonic bor();
  183. mnemonic band();
  184.  
  185. mnemonic and1();
  186. mnemonic and2();
  187. mnemonic and3();
  188. mnemonic and4();
  189.  
  190. mnemonic lsh();
  191. mnemonic lsh1();
  192. mnemonic lsh2();
  193.  
  194. mnemonic rsh();
  195. mnemonic rsh1();
  196. mnemonic rsh2();
  197.  
  198. mnemonic bxor();
  199.  
  200. mnemonics: /* conditions */
  201. mnemonic cmp();
  202. mnemonic eq();
  203.  
  204. mnemonic jmp for jmp(lbl) plain1;
  205. mnemonic jez for jez(lbl) plain1;
  206. mnemonic jnz for jnz(lbl) plain1;
  207.  
  208.  
  209. mnemonic call for call(lbl) plain1;
  210. mnemonic ret();
  211.  
  212. mnemonic cmp0();
  213. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement