home *** CD-ROM | disk | FTP | other *** search
/ APDL Public Domain 1 / APDL_PD1A.iso / program / assembler / as / src / c / help_cop < prev    next >
Encoding:
Text File  |  1992-08-01  |  3.1 KB  |  114 lines

  1.  
  2. /*
  3.  * help_cop.c
  4.  * Copyright © 1992 Niklas Röjemo
  5.  */
  6.  
  7. #include "error.h"
  8. #include "expr.h"
  9. #include "help_cop.h"
  10. #include "input.h"
  11. #include "area.h"
  12. #include "get.h"
  13. #include "option.h"
  14. #include "value.h"
  15. #include "code.h"
  16. #include "fix.h"
  17. #include "reloc.h"
  18.  
  19. int help_copInt(int max,char *msg)
  20. {
  21.   Value i; 
  22.   exprBuild();
  23.   i = exprEval(ValueInt);
  24.   if(i.Tag == ValueInt) {
  25.     if(i.ValueInt.i <0 || i.ValueInt.i >max) {
  26.       error(ErrorError,TRUE,"%d is not a legal %s.",i.ValueInt.i,msg);
  27.       return 0;
  28.     }
  29.   } else {
  30.     error(ErrorError,TRUE,"Illegal expression as %s.",msg);
  31.     return 0;
  32.   }
  33.   return  i.ValueInt.i;
  34. }
  35.  
  36. WORD help_copAddr(WORD ir)
  37. {
  38.   BOOL pre;
  39.   Value offset;
  40.   skipblanks();
  41.   if(inputLook() == ',') { inputSkip(); skipblanks(); }
  42.   else error(ErrorError,TRUE,"Inserting missing comma before address.");
  43.   if(inputLook() == '[') {
  44.     BOOL up = TRUE;
  45.     inputSkip();
  46.     skipblanks();
  47.     ir |= LHS_OP(getCpuReg());       /* Base register */
  48.     skipblanks();
  49.     if(inputLook() == ']') { pre = FALSE; inputSkip(); skipblanks(); }
  50.     else pre = TRUE;
  51.     if(inputLook() == ',') { /* either [base,XX] or [base],XX */
  52.       inputSkip();
  53.       skipblanks();
  54.       if(inputLook() == '+') { inputSkip(); skipblanks(); }
  55.       else if(inputLook() == '-') { inputSkip(); skipblanks(); up = FALSE;}
  56.       if(inputLook() == '#') {
  57.         inputSkip();
  58.         exprBuild();
  59.         if(!up) codeOperator(Op_neg);
  60.         offset = exprEval(ValueInt |ValueCode|ValueLateLabel);
  61.         switch(offset.Tag) {
  62.         case ValueInt:
  63.           ir = fixCopOffset(inputLineNo,ir,offset.ValueInt.i);
  64.           break;
  65.         case ValueCode: case ValueLateLabel:
  66.           relocCopOffset(ir,offset);
  67.           break;
  68.         default:
  69.           error(ErrorError,TRUE,"Illegal offset expression.");
  70.           break;
  71.         }
  72.       } else {
  73.         error(ErrorError,TRUE,"Coprocessor memory instructions can not use register offset.");
  74.       }
  75.       skipblanks();
  76.     } else { /* cop_reg,[base] if this way */
  77.       if(pre)
  78.         error(ErrorError,TRUE,"Illegal character '%c' after base.",inputLook());
  79.       ir |= UP_FLAG;   /* changes offset #-0 to #+0, looks nicer when disassembled. */
  80.     } 
  81.     if(pre) {
  82.       if(inputLook() == ']') { inputSkip(); skipblanks(); }
  83.       else error(ErrorError,TRUE,"Inserting missing ] after address.");
  84.       ir |= PRE_FLAG;
  85.     }
  86.     if(inputLook() == '!') { 
  87.       if(pre) ir |= WB_FLAG;
  88.       else error(ErrorError,TRUE,"Writeback not allowed together with post-(inc/dec)rement.");
  89.       inputSkip();
  90.       skipblanks();
  91.     }
  92.   } else {  /*  cop_reg,Address */
  93.     ir |= PRE_FLAG | LHS_OP(15);
  94.     exprBuild();
  95.     codePosition(areaCurrent);
  96.     codeOperator(Op_sub);
  97.     codeInt(8);
  98.     codeOperator(Op_sub);
  99.     offset = exprEval(ValueInt |ValueCode|ValueLateLabel);
  100.     switch(offset.Tag) {
  101.     case ValueInt:
  102.       ir = fixCopOffset(inputLineNo,ir,offset.ValueInt.i);
  103.       break;
  104.     case ValueCode: case ValueLateLabel:
  105.       relocCopOffset(ir,offset);
  106.       break;
  107.     default:
  108.       error(ErrorError,TRUE,"Illegal address expression.");
  109.       break;
  110.     }
  111.   }
  112.   return ir;
  113. }
  114.