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

  1.  
  2. /*
  3.  * m_cpuctrl.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 "code.h"
  15. #include "area.h"
  16. #include "help_cpu.h"
  17. #include "get.h"
  18. #include "value.h"
  19. #include "fix.h"
  20.  
  21. /** CONTROL **/
  22.  
  23. static void branchlow(BOOL swi, unsigned int ir)
  24. {
  25.   Value im;
  26.   if(swi || inputLook() == '#') {
  27.     if(inputLook() == '#') {
  28.       inputSkip();
  29.       if(swi)
  30.        error(ErrorInfo,TRUE,"Swi is always immediate.");
  31.     }
  32.     exprBuild();
  33.   } else {
  34.     exprBuild();
  35.     codePosition(areaCurrent);   /* It's relative */
  36.     codeOperator(Op_sub);
  37.     codeInt(8);
  38.     codeOperator(Op_sub);
  39.   }
  40.   im = exprEval(ValueInt | ValueCode|ValueLateLabel);
  41.   switch(im.Tag) {
  42.   case ValueInt:
  43.     if(swi)
  44.       ir |= fixSwi(inputLineNo,im.ValueInt.i);
  45.     else
  46.       ir |= fixBranch(inputLineNo,im.ValueInt.i);
  47.     break;
  48.   case ValueCode: case ValueLateLabel:
  49.     if(swi)
  50.       relocSwi(im);
  51.     else
  52.       relocBranch(im);
  53.     break;
  54.   default:
  55.     error(ErrorError,TRUE,swi?"Illegal swi expression.":"Illegal branch destination.");
  56.     break;
  57.   }
  58.   putIns(ir);
  59. }     
  60.  
  61. void m_branch(unsigned int cc)
  62. {
  63.   branchlow(FALSE,cc|0x0a000000);
  64. }
  65.  
  66. void m_swi(unsigned int cc)
  67. {
  68.   branchlow(TRUE,cc|0x0f000000);
  69. }
  70.   
  71.  
  72. /** EXTENSION **/
  73.  
  74. void m_adr(unsigned int cc)
  75. {
  76.   int ir = cc;
  77.   Value im;
  78.   ir |= DST_OP(getCpuReg());
  79.   ir |= LHS_OP(15) | IMM_RHS; /* pc */
  80.   skipblanks();
  81.   if(inputLook() == ',') {inputSkip(); skipblanks();}
  82.   else error(ErrorError,TRUE,"Inserting a comma after dst.");
  83.   exprBuild();
  84.   codePosition(areaCurrent);   /* It's relative */
  85.   codeOperator(Op_sub);
  86.   codeInt(8);
  87.   codeOperator(Op_sub);
  88.   im = exprEval(ValueInt | ValueCode|ValueLateLabel);
  89.   switch(im.Tag) {
  90.   case ValueInt:
  91.     ir = fixAdr(inputLineNo,ir,im.ValueInt.i);
  92.     break;
  93.   case ValueCode: case ValueLateLabel:
  94.     relocAdr(ir,im);
  95.     break;
  96.   default:
  97.     error(ErrorError,TRUE,"Illegal adr expression.");
  98.     break;
  99.   }
  100.   putIns(ir);
  101. }
  102.