Advertisement
Guest User

Untitled

a guest
Dec 18th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.10 KB | None | 0 0
  1. architecture x86 {
  2.  
  3. registers:
  4. storage system_reg[96];
  5.  
  6. view ssz = system_reg[0..32]; /* stack size */
  7. view spn = system_reg [32..64]; /* pointer to stack's beginning */
  8. view ser = system_reg [64..96]; /* error register code */
  9.  
  10.  
  11. memory:
  12. range __ram [0x0..0xFFFFFFFF] {
  13. cell = 8;
  14. endianess = little-endian;
  15. granularity = 0;
  16.  
  17. }
  18.  
  19. range __stack [0x0..0xFFFFFFFF] {
  20. cell = 8;
  21. endianess = little-endian;
  22. granularity = 0;
  23.  
  24. }
  25.  
  26.  
  27. instructions:
  28.  
  29. /* BASE // part 1 */
  30.  
  31. encode __val field = immediate [32] data;
  32. encode __off field = immediate [32] offset; /* offset in memory */
  33.  
  34. instruction nop = { 0000 0000 }; /* perform no operation */
  35. instruction ext = { 0000 0001 }; /* exits program */
  36.  
  37.  
  38. /* STACK // part 2 */
  39.  
  40. instruction push = { 0001 0000, __val as val };
  41. instruction mpush = { 0001 0001, __off as off }; /* pushes from mem storage to stack */
  42.  
  43. instruction pop = { 0001 0010 };
  44. instruction dpl = { 0001 0011 }; /* duplicates last element from stack */
  45. instruction sav = { 0001 0100, __off as off }; /* pops data from stack and stores it in memory */
  46.  
  47. instruction swap = { 0001 0101 }; /* swaps two top value on the stack */
  48. instruction mem = { 0001 0110 }; /* считывает информацию по адресу кот записан в верхнем элементе и записывает на верх стека */
  49. instruction svs = { 0001 0111 }; /* pops data and place in memory to save */
  50.  
  51.  
  52. /* BITWISE OPERATIONS // part 3 */
  53.  
  54. instruction shl = { 0010 0000 }; /* bitwise shift left val a on b */
  55. instruction shl1 = { 0010 0001 }; /* bitwise shift left on 1 */
  56. instruction shl2 = { 0010 0010 }; /* bitwise shift left on 2 */
  57.  
  58. instruction shr = { 0010 0011 }; /* bitwise arithmetic shift right val a on b */
  59. instruction shr1 = { 0010 0100 }; /* bitwise arithmetic shift right on 1 */
  60. instruction shr2 = { 0010 0101 }; /* bitwise arithmetic shift right on 1 */
  61.  
  62. instruction band = { 0010 0110 }; /* bitwise AND */
  63. instruction bor = { 0010 0111 }; /* bitwise OR */
  64. instruction bxor = { 0010 1000 }; /* bitwise XOR */
  65. instruction bnot = { 0010 1001 }; /* bitwise NOT */
  66.  
  67.  
  68. /* MATH // part 4 */
  69.  
  70. instruction add = { 0011 0000 }; /* sum of two val */
  71. instruction sub = { 0011 0001 }; /* subtract of two val */
  72. instruction mul = { 0011 0010 }; /* multiply of two val */
  73. instruction div = { 0011 0011 }; /* divide of two val */
  74.  
  75. instruction neg = { 0011 0100 }; /* negate of two val */
  76. instruction inc = { 0011 0101 }; /* +1 */
  77. instruction dec = { 0011 0110 }; /* -1 */
  78.  
  79. /* COMPARISONS and JUMPS // part 5 */
  80.  
  81. encode __lbl field = immediate [32] offset;
  82.  
  83. instruction eql = { 0100 0000 }; /* 0 if top value equal, else 1*/
  84.  
  85. instruction jmp = { 0100 0001, __lbl as lbl }; /* jump to instruction */
  86. instruction jez = { 0100 0010, __lbl as lbl }; /* jump to instruction if on stack top 0 */
  87. instruction jnz = { 0100 0011, __lbl as lbl }; /* jump to instruction if on stack top !0 */
  88. instruction call = { 0100 0100, __lbl as lbl }; /* куда прыгнуть */
  89. instruction ret = { 0100 0101 }; /* возвращает обратно */
  90.  
  91. instruction com = { 0100 0110 }; /* v1 == v2 | pushes 00
  92. v1 > v2 | pushes 01
  93. v1 < v2 | pushes 11 */
  94.  
  95. mnemonics:
  96.  
  97. format plain1 is "{1}"; /* for numbers */
  98. format mem_ptr is "[{1}]"; /* for memory pointers */
  99.  
  100. /* BASE // part 1 */
  101.  
  102. mnemonic nop();
  103. mnemonic ext();
  104.  
  105.  
  106. /* STACK // part 2 */
  107.  
  108. mnemonic push for push(val) plain1;
  109. mnemonic push for mpush(off) mem_ptr;
  110.  
  111. mnemonic pop();
  112. mnemonic dpl();
  113. mnemonic sav for sav(off) mem_ptr;
  114.  
  115. mnemonic swap();
  116. mnemonic mem();
  117.  
  118.  
  119. /* BITWISE OPERATIONS // part 3 */
  120.  
  121. mnemonic shl();
  122. mnemonic shl1();
  123. mnemonic shl2();
  124.  
  125. mnemonic shr();
  126. mnemonic shr1();
  127. mnemonic shr2();
  128.  
  129. mnemonic band();
  130. mnemonic bor();
  131. mnemonic bxor();
  132. mnemonic bnot();
  133.  
  134.  
  135. /* MATH // part 4*/
  136.  
  137. mnemonic add();
  138. mnemonic sub();
  139. mnemonic mul();
  140. mnemonic div();
  141.  
  142. mnemonic neg();
  143. mnemonic inc();
  144. mnemonic dec();
  145.  
  146.  
  147. /* COMPARISONS and JUMPS // part 5 */
  148.  
  149. mnemonic eql();
  150.  
  151. mnemonic jmp for jmp(lbl) plain1;
  152. mnemonic jez for jez(lbl) plain1;
  153. mnemonic jnz for jnz(lbl) plain1;
  154.  
  155.  
  156. mnemonic call for call(lbl) plain1;
  157. mnemonic ret();
  158.  
  159. mnemonic com();
  160.  
  161. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement