home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / xplatfrm / tierra / parse.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-04-26  |  10.4 KB  |  400 lines

  1. /* parse.c  28-10-91  parser functions for the tierra simulator */
  2. /** Tierra Simulator V3.0: Copyright (c) 1991 Thomas S. Ray **/
  3.  
  4. #include "license.h"
  5.  
  6. #ifndef lint
  7. static char     sccsid[] = "%W%     %G%";
  8. #endif
  9.  
  10. #include "tierra.h"
  11. #include "extern.h"
  12.  
  13. #if INST == 1
  14.  
  15. /* in INST == 1, the array of registers maps into the registers ax, bx, cx, dx
  16.    as follows:  c.re[0] = ax, c.re[1] = bx, c.re[2] = cx, c.re[3] = dx */
  17.  
  18. void SetFlag(ce)
  19. Pcells  ce;
  20. {   ce->c.fl = 1; }
  21.  
  22. void pnop(ci) /* do nothing */
  23. I32s  ci;
  24. {   is.iip = is.dib = 1; }
  25.  
  26. void por1(ci) /* flip low order bit of cx */
  27. I32s  ci;
  28. {   Pcells  ce = cells + ci;
  29.  
  30.     is.dreg = &(ce->c.re[2]);
  31.     is.dval = ce->c.re[2];
  32.     is.iip = is.dib = 1;
  33.     is.dran = SoupSize;
  34. }
  35.  
  36. void pshl(ci) /* shift left all register of cx */
  37. I32s  ci;
  38. {   Pcells  ce = cells + ci;
  39.  
  40.     is.dreg = &(ce->c.re[2]);
  41.     is.dval = ce->c.re[2];
  42.     is.iip = is.dib = 1;
  43.     is.dran = SoupSize;
  44. }
  45.  
  46. void pzero(ci) /* cx = 0 */
  47. I32s  ci;
  48. {   Pcells  ce = cells + ci;
  49.  
  50.     is.dreg = &(ce->c.re[2]);
  51.     is.sval = 0;
  52.     is.iip = is.dib = 1;
  53. }
  54.  
  55. void pif_cz(ci) /* execute next instruction only if cx == 0 */
  56. I32s  ci;
  57. {   Pcells  ce = cells + ci;
  58.  
  59.     is.sval = ce->c.re[2];
  60.     is.iip = is.dib = 1;
  61. }
  62.  
  63. void psub_ab(ci) /* cx = ax - bx */
  64. I32s  ci;
  65. {   Pcells  ce = cells + ci;
  66.  
  67.     is.dreg = &(ce->c.re[2]);
  68.     is.sval = ce->c.re[0];
  69.     is.sval2 = -ce->c.re[1];
  70.     is.iip = is.dib = 1;
  71.     is.dran = SoupSize;
  72. }
  73.  
  74. void psub_ac(ci) /* ax = ax - cx */
  75. I32s  ci;
  76. {   Pcells  ce = cells + ci;
  77.  
  78.     is.dreg = &(ce->c.re[0]);
  79.     is.sval = ce->c.re[0];
  80.     is.sval2 = -ce->c.re[2];
  81.     is.iip = is.dib = 1;
  82.     is.dmod = SoupSize;
  83. }
  84.  
  85. void pinc_a(ci) /* ax++ */
  86. I32s  ci;
  87. {   Pcells  ce = cells + ci;
  88.  
  89.     is.dreg = &(ce->c.re[0]);
  90.     is.sval = ce->c.re[0];
  91.     is.sval2 = 1;
  92.     is.iip = is.dib = 1;
  93.     is.dmod = SoupSize;
  94. }
  95.  
  96. void pinc_b(ci) /* bx++ */
  97. I32s  ci;
  98. {   Pcells  ce = cells + ci;
  99.  
  100.     is.dreg = &(ce->c.re[1]);
  101.     is.sval = ce->c.re[1];
  102.     is.sval2 = 1;
  103.     is.iip = is.dib = 1;
  104.     is.dmod = SoupSize;
  105. }
  106.  
  107. void pdec_c(ci) /* cx-- */
  108. I32s  ci;
  109. {   Pcells  ce = cells + ci;
  110.  
  111.     is.dreg = &(ce->c.re[2]);
  112.     is.sval = ce->c.re[2];
  113.     is.sval2 = -1;
  114.     is.iip = is.dib = 1;
  115.     is.dran = SoupSize;
  116. }
  117.  
  118. void pinc_c(ci) /* cx++ */
  119. I32s  ci;
  120. {   Pcells  ce = cells + ci;
  121.  
  122.     is.dreg = &(ce->c.re[2]);
  123.     is.sval = ce->c.re[2];
  124.     is.sval2 = 1;
  125.     is.iip = is.dib = 1;
  126.     is.dran = SoupSize;
  127. }
  128.  
  129. void ppush_ax(ci) /* push ax onto stack */
  130. I32s  ci;
  131. {   Pcells  ce = cells + ci;
  132.  
  133.     is.sval = ce->c.re[0];
  134.     is.iip = is.dib = 1;
  135. }
  136.  
  137. void ppush_bx(ci) /* push bx onto stack */
  138. I32s  ci;
  139. {   Pcells  ce = cells + ci;
  140.  
  141.     is.sval = ce->c.re[1];
  142.     is.iip = is.dib = 1;
  143. }
  144.  
  145. void ppush_cx(ci) /* push cx onto stack */
  146. I32s  ci;
  147. {   Pcells  ce = cells + ci;
  148.  
  149.     is.sval = ce->c.re[2];
  150.     is.iip = is.dib = 1;
  151. }
  152.  
  153. void ppush_dx(ci) /* push dx onto stack */
  154. I32s  ci;
  155. {   Pcells  ce = cells + ci;
  156.  
  157.     is.sval = ce->c.re[3];
  158.     is.iip = is.dib = 1;
  159. }
  160.  
  161. void ppop_ax(ci) /* pop ax off of stack */
  162. I32s  ci;
  163. {   Pcells  ce = cells + ci;
  164.  
  165.     is.dreg = &(ce->c.re[0]);
  166.     is.iip = is.dib = 1;
  167.     is.dmod = SoupSize;
  168. }
  169.  
  170. void ppop_bx(ci) /* pop bx off of stack */
  171. I32s  ci;
  172. {   Pcells  ce = cells + ci;
  173.  
  174.     is.dreg = &(ce->c.re[1]);
  175.     is.iip = is.dib = 1;
  176.     is.dmod = SoupSize;
  177. }
  178.  
  179. void ppop_cx(ci) /* pop cx off of stack */
  180. I32s  ci;
  181. {   Pcells  ce = cells + ci;
  182.  
  183.     is.dreg = &(ce->c.re[2]);
  184.     is.iip = is.dib = 1;
  185.     is.dran = SoupSize;
  186. }
  187.  
  188. void ppop_dx(ci) /* pop dx off of stack */
  189. I32s  ci;
  190. {   Pcells  ce = cells + ci;
  191.  
  192.     is.dreg = &(ce->c.re[3]);
  193.     is.iip = is.dib = 1;
  194.     is.dran = SoupSize;
  195. }
  196.  
  197. void ptjmp(ci) /* outward template jump */
  198. I32s  ci;
  199. {   Pcells  ce = cells + ci;
  200.     I32s    a, s = 0;
  201.  
  202.     is.dreg  = &(ce->c.ip); /* destination register for address */
  203.     is.dreg2 = &(ce->c.re[3]); /* destination register for template size */
  204.     a = ad(ce->c.ip + 1); /* a = address of start of template */
  205.     while(1) /* find size of template, s = size */
  206.     {   if(soup[ad(a + s)][ce->c.tr].inst != 0 &&
  207.            soup[ad(a + s)][ce->c.tr].inst != 1)
  208.             break;
  209.         s++;
  210.     }
  211.     is.sval2 = s;  /* size of template */
  212.     is.dran2 = SoupSize;
  213.     is.dmod  = SoupSize;
  214.     is.dval  = ad(a + s + 1); /* start address for forward search */
  215.     is.dval2 = ad(a - s - 1); /* start address for backward search */
  216.     is.mode  = 0; /* outward jump */
  217.     is.mode2 = 0; /* complementary templates */
  218.     is.iip = 0; is.dib = 1;
  219. }
  220.  
  221. void ptjmpb(ci) /* backward template jump */
  222. I32s  ci;
  223. {   Pcells  ce = cells + ci;
  224.     I32s    a, s = 0;
  225.  
  226.     is.dreg  = &(ce->c.ip); /* destination register for address */
  227.     is.dreg2 = &(ce->c.re[3]); /* destination register for template size */
  228.     a = ad(ce->c.ip + 1); /* a = address of start of template */
  229.     while(1) /* find size of template, s = size */
  230.     {   if(soup[ad(a + s)][ce->c.tr].inst != 0 &&
  231.            soup[ad(a + s)][ce->c.tr].inst != 1)
  232.             break;
  233.         s++;
  234.     }
  235.     is.sval2 = s;  /* size of template */
  236.     is.dran2 = SoupSize;
  237.     is.dmod  = SoupSize;
  238.     is.dval  = ad(a + s + 1); /* start address for forward search */
  239.     is.dval2 = ad(a - s - 1); /* start address for backward search */
  240.     is.mode  = 2; /* backward jump */
  241.     is.mode2 = 0; /* complementary templates */
  242.     is.iip = 0; is.dib = 1;
  243. }
  244.  
  245. void ptcall(ci) /* push ip to stack, outward template jump */
  246. I32s  ci;
  247. {   Pcells  ce = cells + ci;
  248.     I32s    a, s = 0;
  249.  
  250.     is.dreg  = &(ce->c.ip); /* destination register for address */
  251.     is.dreg2 = &(ce->c.re[3]); /* destination register for template size */
  252.     a = ad(ce->c.ip + 1); /* a = address of start of template */
  253.     while(1) /* find size of template, s = size */
  254.     {   if(soup[ad(a + s)][ce->c.tr].inst != 0 &&
  255.            soup[ad(a + s)][ce->c.tr].inst != 1)
  256.             break;
  257.         s++;
  258.     }
  259.     is.sval  = ce->c.ip + s + 1;    /* address to be pushed onto stack */
  260.     is.sval2 = s;  /* size of template */
  261.     is.dran2 = SoupSize;
  262.     is.dmod  = SoupSize;
  263.     is.dval  = ad(a + s + 1); /* start address for forward search */
  264.     is.dval2 = ad(a - s - 1); /* start address for backward search */
  265.     is.mode  = 0; /* outward jump */
  266.     is.mode2 = 0; /* complementary templates */
  267.     is.iip = 0; is.dib = 1;
  268. }
  269.  
  270. void pret(ci) /* pop ip from stack */
  271. I32s  ci;
  272. {   Pcells  ce = cells + ci;
  273.  
  274.     is.dreg = &(ce->c.ip);
  275.     is.iip = 0; is.dib = 1;
  276.     is.dmod = SoupSize;
  277. }
  278.  
  279. void pmov_dc(ci) /* dx = cx */
  280. I32s  ci;
  281. {   Pcells  ce = cells + ci;
  282.  
  283.     is.dreg = &(ce->c.re[3]);
  284.     is.sval = ce->c.re[2];
  285.     is.iip = is.dib = 1;
  286. }
  287.  
  288. void pmov_ba(ci) /* bx = ax */
  289. I32s  ci;
  290. {   Pcells  ce = cells + ci;
  291.  
  292.     is.dreg = &(ce->c.re[1]);
  293.     is.sval = ce->c.re[0];
  294.     is.iip = is.dib = 1;
  295. }
  296.  
  297. void pmov_iab(ci)
  298. I32s  ci;
  299. {   Pcells  ce = cells + ci;
  300.  
  301.     is.dins = &soup[ce->c.re[0]][ce->c.tr];
  302.     is.sins = &soup[ce->c.re[1]][ce->c.tr];
  303.     is.dval = ce->c.re[0];
  304.     is.sval = ce->c.re[1];
  305.     is.dtra = is.stra = ce->c.tr;
  306.     is.iip = is.dib = 1;
  307. }
  308.  
  309. void padr(ci) /* search outward for template, return address in ax */
  310. I32s  ci; /* return template size in cx */
  311. {   Pcells  ce = cells + ci;
  312.     I32s    a, s = 0;
  313.  
  314.     is.dreg  = &(ce->c.re[0]); /* destination register for address */
  315.     is.dreg2 = &(ce->c.re[2]); /* destination register for template size */
  316.     a = ad(ce->c.ip + 1); /* a = address of start of template */
  317.     while(1) /* find size of template, s = size */
  318.     {   if(soup[ad(a + s)][ce->c.tr].inst != 0 &&
  319.            soup[ad(a + s)][ce->c.tr].inst != 1)
  320.             break;
  321.         s++;
  322.     }
  323.     is.sval2 = s;  /* size of template */
  324.     is.dran2 = SoupSize;
  325.     is.dmod  = SoupSize;
  326.     is.dval  = ad(a + s + 1); /* start address for forward search */
  327.     is.dval2 = ad(a - s - 1); /* start address for backward search */
  328.     is.mode  = 0; /* outward jump */
  329.     is.mode2 = 0; /* complementary templates */
  330.     is.iip = 0; is.dib = 1;
  331. }
  332.  
  333. void padrb(ci) /* search backward for template, return address in ax */
  334. I32s  ci; /* return template size in cx */
  335. {   Pcells  ce = cells + ci;
  336.     I32s    a, s = 0;
  337.  
  338.     is.dreg  = &(ce->c.re[0]); /* destination register for address */
  339.     is.dreg2 = &(ce->c.re[2]); /* destination register for template size */
  340.     a = ad(ce->c.ip + 1); /* a = address of start of template */
  341.     while(1) /* find size of template, s = size */
  342.     {   if(soup[ad(a + s)][ce->c.tr].inst != 0 &&
  343.            soup[ad(a + s)][ce->c.tr].inst != 1)
  344.             break;
  345.         s++;
  346.     }
  347.     is.sval2 = s;  /* size of template */
  348.     is.dran2 = SoupSize;
  349.     is.dmod  = SoupSize;
  350.     is.dval  = ad(a + s + 1); /* start address for forward search */
  351.     is.dval2 = ad(a - s - 1); /* start address for backward search */
  352.     is.mode  = 2; /* backward jump */
  353.     is.mode2 = 0; /* complementary templates */
  354.     is.iip = s + 1; is.dib = 1;
  355. }
  356.  
  357. void padrf(ci) /* search forward for template, return address in ax */
  358. I32s  ci; /* return template size in cx */
  359. {   Pcells  ce = cells + ci;
  360.     I32s    a, s = 0;
  361.  
  362.     is.dreg  = &(ce->c.re[0]); /* destination register for address */
  363.     is.dreg2 = &(ce->c.re[2]); /* destination register for template size */
  364.     a = ad(ce->c.ip + 1); /* a = address of start of template */
  365.     while(1) /* find size of template, s = size */
  366.     {   if(soup[ad(a + s)][ce->c.tr].inst != 0 &&
  367.            soup[ad(a + s)][ce->c.tr].inst != 1)
  368.             break;
  369.         s++;
  370.     }
  371.     is.sval2 = s;  /* size of template */
  372.     is.dran2 = SoupSize;
  373.     is.dmod  = SoupSize;
  374.     is.dval  = ad(a + s + 1); /* start address for forward search */
  375.     is.dval2 = ad(a - s - 1); /* start address for backward search */
  376.     is.mode  = 1; /* forward jump */
  377.     is.mode2 = 0; /* complementary templates */
  378.     is.iip = s + 1; is.dib = 1;
  379. }
  380.  
  381. void pmal(ci)  /* allocate space for a new cell */
  382. I32s  ci;  /* allocate space for a new cell */
  383. {   Pcells  ce = cells + ci;
  384.  
  385.     is.dreg = &(ce->c.re[0]);
  386.     is.sval = ce->c.re[2];
  387.     is.dmod = SoupSize;
  388.     is.dtra = ce->c.tr;
  389.     is.mode = 2; /* only write privelages protected */
  390.     is.iip = is.dib = 1;
  391. }
  392.  
  393. void pdivide(ci)  /* give life to new cell by puting in queue */
  394. I32s  ci;
  395. {   is.mode = 2;  /* full division */
  396.     is.iip = is.dib = 1;
  397. }
  398.  
  399. #endif  /* end of INST 1 */
  400.