home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / lang_asm / as0 / do0.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-04-30  |  2.9 KB  |  165 lines

  1. /*
  2.  *    MC6800/02 specific processing
  3.  */
  4.  
  5. /* addressing modes */
  6. #define IMMED    0    /* immediate */
  7. #define IND    1    /* indexed */
  8. #define OTHER    2    /* NOTA */
  9.  
  10.  
  11. char *skip_white();   /* this line added to keep TurboC happy 4/30/88 jec */
  12.  
  13. /*
  14.  *    localinit --- machine specific initialization
  15.  */
  16. localinit()
  17. {
  18. }
  19.  
  20. /*
  21.  *    do_op --- process mnemonic
  22.  *
  23.  *    Called with the base opcode and it's class. Optr points to
  24.  *    the beginning of the operand field.
  25.  */
  26. do_op(opcode,class)
  27. int opcode;    /* base opcode */
  28. int class;    /* mnemonic class */
  29. {
  30.     int    dist;    /* relative branch distance */
  31.     int    amode;    /* indicated addressing mode */
  32.     char    *peek;
  33.  
  34.     /* guess at addressing mode */
  35.     peek = Optr;
  36.     amode = OTHER;
  37.     while( !delim(*peek) && *peek != EOS)  /* check for comma in operand field */
  38.         if( *peek++ == ',' ){
  39.             amode = IND;
  40.             break;
  41.             }
  42.     if( *Optr == '#' ) amode = IMMED;
  43.  
  44.     switch(class){
  45.         case INH:            /* inherent addressing */
  46.             emit(opcode);
  47.             return;
  48.         case GEN:            /* general addressing */
  49.             do_gen(opcode,amode);
  50.             return;
  51.         case REL:            /* relative branches */
  52.             eval();
  53.             dist = Result - (Pc+2);
  54.             emit(opcode);
  55.             if( (dist >127 || dist <-128) && Pass==2){
  56.                 error("Branch out of Range");
  57.                 emit(lobyte(-2));
  58.                 return;
  59.                 }
  60.             emit(lobyte(dist));
  61.             return;
  62.         case NOIMM:
  63.             if( amode == IMMED){
  64.                 error("Immediate Addressing Illegal");
  65.                 return;
  66.                 }
  67.             if((opcode == 0x8D) && (amode == IND)){
  68.                 Cycles-=2;
  69.                 }
  70.             do_gen(opcode,amode);
  71.  
  72.             return;
  73.         case LONGIMM:
  74.             if( amode == IMMED ){
  75.                 emit(opcode);
  76.                 Optr++;
  77.                 eval();
  78.                 eword(Result);
  79.                 return;
  80.                 }
  81.             do_gen(opcode,amode);
  82.             return;
  83.         case GRP2:
  84.             if( amode == IND ){
  85.                 Cycles++;
  86.                 do_indexed(opcode);
  87.                 return;
  88.                 }
  89.             /* extended addressing */
  90.             eval();
  91.             emit(opcode+0x10);
  92.             eword(Result);
  93.             return;
  94.         default:
  95.             fatal("Error in Mnemonic table");
  96.         }
  97. }
  98.  
  99. /*
  100.  *    do_gen --- process general addressing modes
  101.  */
  102. do_gen(op,mode)
  103. int    op;
  104. int    mode;
  105. {
  106.     if( mode == IMMED){
  107.         Optr++;
  108.         emit(op);
  109.         eval();
  110.         emit(lobyte(Result));
  111.         return;
  112.         }
  113.     else if( mode == IND ){
  114.         Cycles+=3;
  115.         do_indexed(op+0x20);
  116.         return;
  117.         }
  118.     else if( mode == OTHER){
  119.         eval();
  120.         if(Force_word){
  121.             emit(op+0x30);
  122.             eword(Result);
  123.             Cycles+=2;
  124.             return;
  125.             }
  126.         if(Force_byte){
  127.             emit(op+0x10);
  128.             emit(lobyte(Result));
  129.             Cycles++;
  130.             return;
  131.             }
  132.         if(Result>=0 && Result <=0xFF){
  133.             emit(op+0x10);
  134.             emit(lobyte(Result));
  135.             Cycles++;
  136.             return;
  137.             }
  138.         else {
  139.             emit(op+0x30);
  140.             eword(Result);
  141.             Cycles+=2;
  142.             return;
  143.             }
  144.         }
  145.     else {
  146.         error("Unknown Addressing Mode");
  147.         return;
  148.         }
  149. }
  150.  
  151. /*
  152.  *    do_indexed --- handle all wierd stuff for indexed addressing
  153.  */
  154. do_indexed(op)
  155. int op;
  156. {
  157.     emit(op);
  158.     eval();
  159.     if( mapdn(*++Optr) != 'x' )
  160.         warn("Indexed Addressing Assumed");
  161.     if( Result < 0 || Result > 255)
  162.         warn("Value Truncated");
  163.     emit(lobyte(Result));
  164. }
  165.