home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / cpm / misc / smc203.ark / CC41.C < prev    next >
Encoding:
Text File  |  1983-07-28  |  5.8 KB  |  369 lines

  1.  
  2. /*
  3. ** print all assembler info before any code is generated
  4. */
  5. header()  {
  6.   beglab=getlabel();
  7.  
  8. #ifndef LINK
  9.   if(beglab < 3)
  10. #endif /* LINK */
  11.  
  12.     {
  13.  
  14.  
  15. #ifdef LINK
  16.     jump(beglab);
  17. #endif /* LINK */
  18.     }
  19.   }
  20.  
  21. /*
  22. ** print any assembler stuff needed at the end
  23. */
  24. trailer()  {  
  25.  
  26.  
  27.   ol("END");
  28.   }
  29.  
  30. /*
  31. ** load # args before function call
  32. */
  33. loadargc(val) int val; {
  34.  
  35. #ifdef HASH
  36.   if(search("NOCCARGC", macn, NAMESIZE+2, MACNEND, MACNBR, 0)==0) {
  37. #else /* HASH */
  38.   if(findmac("NOCCARGC")==0) {
  39. #endif /* HASH */
  40.  
  41.     ot("MVI A,");
  42.     outdec(val);
  43.     nl();
  44.     }
  45.   }
  46.  
  47. /*
  48. ** declare entry point
  49. */
  50. entry() {
  51. #ifdef LINK
  52.   if (!m80flg) {
  53.     ot("PUBLIC ");
  54.     ol(ssname);
  55.     }
  56. #endif /* LINK */
  57.   outstr(ssname);
  58.   col();
  59.  
  60. #ifdef LINK
  61.   if (m80flg) {
  62.     col();
  63.     }
  64. #endif /* LINK */
  65.   nl();
  66.   }
  67.  
  68. /*
  69. ** declare external reference
  70. */
  71. external(name) char *name; {
  72. #ifdef LINK
  73.     ot("EXTRN ");
  74.     outstr(name);
  75.     nl();
  76. #endif
  77.     }
  78.  
  79. /*
  80. ** fetch object indirect to primary register
  81. */
  82. indirect(lval) int lval[]; {
  83.   if(lval[1]==CCHAR) zzcall("CCGCHAR");
  84.   else               zzcall("CCGINT");
  85.   }
  86.  
  87. /*
  88. ** fetch a static memory cell into primary register
  89. */
  90. getmem(lval)  int lval[]; {
  91.   char *sym;
  92.   sym=lval[0];
  93.   if((sym[IDENT]!=POINTER)&(sym[TYPE]==CCHAR)) {
  94.     ot("LDA ");
  95.     outstr(sym+NAME);
  96.     nl();
  97.     zzcall("CCSXT");
  98.     }
  99.   else {
  100.     ot("LHLD ");
  101.     outstr(sym+NAME);
  102.     nl();
  103.     }
  104.   }
  105.  
  106. /*
  107. ** fetch addr of the specified symbol into primary register
  108. */
  109. getloc(sym)  char *sym; {
  110.   const(getint(sym+OFFSET, OFFSIZE)-csp);
  111.   ol("DAD SP");
  112.   }
  113.  
  114. /*
  115. ** store primary register into static cell
  116. */
  117. putmem(lval)  int lval[]; {
  118.   char *sym;
  119.   sym=lval[0];
  120.   if((sym[IDENT]!=POINTER)&(sym[TYPE]==CCHAR)) {
  121.     ol("MOV A,L");
  122.     ot("STA ");
  123.     }
  124.   else ot("SHLD ");
  125.   outstr(sym+NAME);
  126.   nl();
  127.   }
  128.  
  129. /*
  130. ** put on the stack the type object in primary register
  131. */
  132. putstk(lval) int lval[]; {
  133.   if(lval[1]==CCHAR) {
  134.     ol("MOV A,L");
  135.     ol("STAX D");
  136.     }
  137.   else zzcall("CCPINT");
  138.   }
  139.  
  140. /*
  141. ** move primary register to secondary
  142. */
  143. move() {
  144.   ol("MOV D,H");
  145.   ol("MOV E,L");
  146.   }
  147.  
  148. /*
  149. ** swap primary and secondary registers
  150. */
  151. swap() {
  152.   ol("XCHG;;");  /* peephole() uses trailing ";;" */
  153.   }
  154.  
  155. /*
  156. ** partial instruction to get immediate value
  157. ** into the primary register
  158. */
  159. immed() {
  160.   ot("LXI H,");
  161.   }
  162.  
  163. /*
  164. ** partial instruction to get immediate operand
  165. ** into secondary register
  166. */
  167. immed2() {
  168.   ot("LXI D,");
  169.   }
  170.  
  171. /*
  172. ** push primary register onto stack
  173. */
  174. zzpush() {
  175.   ol("PUSH H");
  176.   csp=csp-BPW;
  177.   }
  178.  
  179. /*
  180. ** unpush or pop as required
  181. */
  182. smartpop(lval, start) int lval[]; char *start; {
  183.   if(lval[5])  zzpop(); /* secondary was used */
  184.   else unpush(start);
  185.   }
  186.  
  187. /*
  188. ** replace a push with a swap
  189. */
  190. unpush(dest) char *dest; {
  191.   int i;
  192.   char *sour;
  193.  
  194. #ifdef TAB
  195.   sour="\tXCHG;;";  /* peephole() uses trailing ";;" */
  196. #else /* TAB */
  197.   sour=" XCHG;;";  /* peephole() uses trailing ";;" */
  198. #endif /* TAB */
  199.  
  200.   while(*sour) *dest++ = *sour++;
  201.   sour=stagenext;
  202.   while(--sour > dest) { /* adjust stack references */
  203.  
  204. #ifdef TAB
  205.     if(streq(sour,"\tDAD SP")) {
  206. #else /* TAB */
  207.     if(streq(sour," DAD SP")) {
  208. #endif /* TAB */
  209.  
  210.       --sour;
  211.       i=BPW;
  212.       while(numeric(*(--sour))) {
  213.         if((*sour = *sour-i) < '0') {
  214.           *sour = *sour+10;
  215.           i=1;
  216.           }
  217.         else i=0;
  218.         }
  219.       }
  220.     }
  221.   csp=csp+BPW;
  222.   }
  223.  
  224. /*
  225. ** pop stack to the secondary register
  226. */
  227. zzpop() {
  228.   ol("POP D");
  229.   csp=csp+BPW;
  230.   }
  231.  
  232. /*
  233. ** swap primary register and stack
  234. */
  235. swapstk() {
  236.   ol("XTHL");
  237.   }
  238.  
  239. /*
  240. ** process switch statement
  241. */
  242. sw() {
  243.   zzcall("CCSWITCH");
  244.   }
  245.  
  246. /*
  247. ** call specified subroutine name
  248. */
  249. zzcall(sname)  char *sname; {
  250.   ot("CALL ");
  251.   outstr(sname);
  252.   nl();
  253.   }
  254.  
  255. /*
  256. ** return from subroutine
  257. */
  258. zzret() {
  259.   ol("RET");
  260.   }
  261.  
  262. /*
  263. ** perform subroutine call to value on stack
  264. */
  265. callstk() {
  266.   immed();
  267.   outstr("$+5");
  268.   nl();
  269.   swapstk();
  270.   ol("PCHL");
  271.   csp=csp+BPW;
  272.   }
  273.  
  274. /*
  275. ** jump to internal label number
  276. */
  277. jump(label)  int label; {
  278.   ot("JMP ");
  279.   printlabel(label);
  280.   nl();
  281.   }
  282.  
  283. /*
  284. ** test primary register and jump if false
  285. */
  286. testjump(label)  int label; {
  287.   ol("MOV A,H");
  288.   ol("ORA L");
  289.   ot("JZ ");
  290.   printlabel(label);
  291.   nl();
  292.   }
  293.  
  294. /*
  295. ** test primary register against zero and jump if false
  296. */
  297. #ifdef FULLC
  298. zerojump(oper, label, lval) int (*oper)(), label, lval[]; {
  299.   clearstage(lval[7], 0);  /* purge conventional code */
  300.   (*oper)(label);
  301.   }
  302. #else /* FULLC */
  303. zerojump(oper, label, lval) int oper, label, lval[]; {
  304.   clearstage(lval[7], 0);  /* purge conventional code */
  305.   oper(label);
  306.   }
  307. #endif /* FULLC */
  308.  
  309. /*
  310. ** define storage according to size
  311. */
  312. defstorage(size) int size; {
  313.   if(size==1) ot("DB ");
  314.   else        ot("DW ");
  315.   }
  316.  
  317. /*
  318. ** point to following object(s)
  319. */
  320. point() {
  321.   ol("DW $+2");
  322.   }
  323.  
  324. /*
  325. ** modify stack pointer to value given
  326. */
  327. modstk(newsp, save)  int newsp, save; {
  328.   int k;
  329.   k=newsp-csp;
  330.   if(k==0)return newsp;
  331.   if(k>=0) {
  332.     if(k<7) {
  333.       if(k&1) {
  334.         ol("INX SP");
  335.         k--;
  336.         }
  337.       while(k) {
  338.         ol("POP B");
  339.         k=k-BPW;
  340.         }
  341.       return newsp;
  342.       }
  343.     }
  344.   if(k<0) {
  345.     if(k>-7) {
  346.       if(k&1) {
  347.         ol("DCX SP");
  348.         k++;
  349.         }
  350.       while(k) {
  351.         ol("PUSH B");
  352.         k=k+BPW;
  353.         }
  354.       return newsp;
  355.       }
  356.     }
  357.   if(save) swap();
  358.   const(k);
  359.   ol("DAD SP");
  360.   ol("SPHL");
  361.   if(save) swap();
  362.   return newsp;
  363.   }
  364.  
  365. /*
  366. ** double primary register
  367. */
  368. doublereg() {ol("DAD H");}
  369.       DEF D?CC1     C   F⌠CC11    C   Im(