home *** CD-ROM | disk | FTP | other *** search
/ APDL Public Domain 1 / APDL_PD1A.iso / program / assembler / as / src / c / m_cpu < prev    next >
Encoding:
Text File  |  1992-07-21  |  3.2 KB  |  193 lines

  1.  
  2. /*
  3.  * m_cpu.c
  4.  * Copyright © 1992 Niklas Röjemo
  5.  */
  6.  
  7. #include "mnemonics.h"
  8. #include "error.h"
  9. #include "option.h"
  10. #include "put.h"
  11. #include "input.h"
  12. #include "global.h"
  13. #include "expr.h"
  14. #include "area.h"
  15. #include "get.h"
  16. #include "m_cpu.h"
  17.  
  18.  
  19.  
  20. /** DATA dst=lhs<op>rhs **/
  21.  
  22. static void dstlhsrhs(unsigned int ir)
  23. {
  24.   unsigned int op;
  25.   op = getCpuReg();
  26.   ir |= DST_OP(op);
  27.   skipblanks();
  28.   if(inputLook() == ',') {inputSkip(); skipblanks();}
  29.   else error(ErrorError,TRUE,"Inserting a comma after dst.");
  30.   op = getCpuReg();
  31.   ir |= LHS_OP(op);
  32.   skipblanks();
  33.   if(inputLook() == ',') {inputSkip(); skipblanks();}
  34.   else error(ErrorError,TRUE,"Inserting a comma after lhs.");
  35.   ir = getRhs(FALSE,ir);
  36.   putIns(ir);
  37. }
  38.  
  39. static void dstrhs(unsigned int ir)
  40. {
  41.   unsigned int op;
  42.   op = getCpuReg();
  43.   ir |= DST_OP(op);
  44.   skipblanks();
  45.   if(inputLook() == ',') {inputSkip(); skipblanks();}
  46.   else error(ErrorError,TRUE,"Inserting a comma after dst.");
  47.   ir = getRhs(FALSE,ir);
  48.   putIns(ir);
  49. }
  50.  
  51. void m_adc(unsigned int cc)
  52. {
  53.    dstlhsrhs(cc|M_ADC);
  54. }
  55.  
  56. void m_add(unsigned int cc)
  57. {
  58.    dstlhsrhs(cc|M_ADD);
  59. }
  60.  
  61. void m_and(unsigned int cc)
  62. {
  63.    dstlhsrhs(cc|M_AND);
  64. }
  65.  
  66. void m_bic(unsigned int cc)
  67. {
  68.    dstlhsrhs(cc|M_BIC);
  69. }
  70.  
  71.  
  72. void m_eor(unsigned int cc)
  73. {
  74.    dstlhsrhs(cc|M_EOR);
  75. }
  76.  
  77. void m_mov(unsigned int cc)
  78. {
  79.    dstrhs(cc|M_MOV);
  80. }
  81.  
  82. void m_mvn(unsigned int cc)
  83. {
  84.    dstrhs(cc|M_MVN);
  85. }
  86.  
  87. void m_orr(unsigned int cc)
  88. {
  89.    dstlhsrhs(cc|M_ORR);
  90. }
  91.  
  92. void m_rsb(unsigned int cc)
  93. {
  94.    dstlhsrhs(cc|M_RSB);
  95. }
  96.  
  97. void m_rsc(unsigned int cc)
  98. {
  99.    dstlhsrhs(cc|M_RSC);
  100. }
  101.  
  102. void m_sbc(unsigned int cc)
  103. {
  104.    dstlhsrhs(cc|M_SBC);
  105. }
  106.  
  107. void m_sub(unsigned int cc)
  108. {
  109.    dstlhsrhs(cc|M_SUB);
  110. }
  111.  
  112. /** DATA test **/
  113.  
  114. static void lhsrhs(unsigned int ir)
  115. {
  116.   unsigned int op;
  117.   op = getCpuReg();
  118.   ir |= LHS_OP(op);
  119.   skipblanks();
  120.   if(inputLook() == ',') {inputSkip(); skipblanks();}
  121.   else error(ErrorError,TRUE,"Inserting a comma after lhs.");
  122.   ir = getRhs(FALSE,ir);
  123.   putIns(ir);
  124. }
  125.  
  126. void m_cmn(unsigned int cc)
  127. {
  128.    lhsrhs(cc|M_CMN);
  129. }
  130.  
  131. void m_cmp(unsigned int cc)
  132. {
  133.    lhsrhs(cc|M_CMP);
  134. }
  135.  
  136. void m_teq(unsigned int cc)
  137. {
  138.    lhsrhs(cc|M_TEQ);
  139. }
  140.  
  141. void m_tst(unsigned int cc)
  142. {
  143.    lhsrhs(cc|M_TST);
  144. }
  145.  
  146. /** DATA 1a **/
  147.  
  148. extern int pedantic;
  149.  
  150. static void onlyregs(BOOL acc, unsigned int ir)
  151. {
  152.   WORD  dst,rhs,lhs;
  153.   dst = getCpuReg();
  154.   ir |= DST_MUL(dst);
  155.   skipblanks();
  156.   if(inputLook() == ',') {inputSkip(); skipblanks();}
  157.   else error(ErrorError,TRUE,"Inserting a comma after dst.");
  158.   lhs = getCpuReg();
  159.   skipblanks();
  160.   if(inputLook() == ',') {inputSkip(); skipblanks();}
  161.   else error(ErrorError,TRUE,"Inserting a comma after lhs.");
  162.   rhs = getCpuReg();
  163.   if(dst == lhs) {
  164.     if(dst == rhs)
  165.       error(ErrorError,TRUE,"Destination and left operand are the same register %d.",dst);
  166.     else {
  167.       if(pedantic)
  168.         error(ErrorInfo,TRUE,"Changing order of operands in %s.",acc?"mla":"mul");
  169.       { int t = lhs; lhs = rhs; rhs = t; }
  170.     }
  171.   }
  172.   ir |= LHS_MUL(lhs);
  173.   ir |= RHS_MUL(rhs);
  174.   skipblanks();
  175.   if(acc) {
  176.     if(inputLook() == ',') {inputSkip(); skipblanks();}
  177.     else error(ErrorError,TRUE,"Inserting a comma after rhs.");
  178.     ir |= ACC_MUL(getCpuReg());
  179.     skipblanks();
  180.   }
  181.   putIns(ir);
  182. }
  183.  
  184. void m_mla(unsigned int cc)
  185. {
  186.    onlyregs(TRUE,cc|M_MLA);
  187. }
  188.  
  189. void m_mul(unsigned int cc)
  190. {
  191.    onlyregs(FALSE,cc|M_MUL);
  192. }
  193.