home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 363_02 / trapcc.c < prev   
C/C++ Source or Header  |  1991-12-17  |  5KB  |  141 lines

  1. /***********************************************************************
  2.  *
  3.  *
  4.  *      TRAPCC - Routine for 68020 Assembler
  5.  *          Routine for instructions:
  6.  *           TRAPCC (TRAPHS)   TRAPGT    TRAPLT      TRAPRA
  7.  *           TRAPCS (TRAPLO)   TRAPHI    TRAPMI      TRAPSR
  8.  *           TRAPEQ            TRAPLE    TRAPNE      TRAPVC
  9.  *           TRAPGE            TRAPLS    TRAPPL      TRAPVS
  10.  *
  11.  *  int trapcc(instruction *tablePtr, int size, char *label, char *op,
  12.  *                                                          int *errorPtr)
  13.  *
  14.  *      tablePtr - pointer to the instruction table,
  15.  *      size     - 0 indicates no immediate operand, WORD/LONG valid sizes
  16.  *                 of the immediate operand,
  17.  *      label    - pointer to the label string, empty string if no label
  18.  *      op       - pointer to the input string,
  19.  *      errorPtr - pointer to the error flag.
  20.  *
  21.  *      The routine returns an error code in *errorPtr using the standard
  22.  *      mechanism.
  23.  *
  24.  *
  25.  *      Author: Andrew E. Romer. Version 1.0
  26.  *      38 Bolsover Road, Worthing, West Sussex, England BN13 1NT.
  27.  *
  28.  *      Date: May 1991
  29.  *
  30.  ***********************************************************************/
  31.  
  32.  
  33. #include <stdio.h>
  34. #include <ctype.h>
  35. #include "asm.h"
  36.  
  37. extern long loc;
  38. extern char pass2;
  39. extern char noOperand;      /* TRUE if the instruction has no operand.
  40.                              * Used by listLine. */
  41.  
  42. int trapcc(instruction *tablePtr, int size, char *label, char *op,
  43.                                                             int *errorPtr)
  44.     {
  45.     variant *variantPtr;
  46.     opDescriptor source;
  47.  
  48. /* op points to the first character of the operand field */
  49.  
  50. /* Move location counter to a word boundary and fix the listing before
  51.  * assembling the instruction */
  52.  
  53.     if (loc & 1)                         /* if not at word boundary */
  54.         {
  55.         loc++;
  56.         listLoc();
  57.         }
  58.  
  59.     if (*label)
  60.         {
  61.         create(label, loc, errorPtr);
  62.         if (*errorPtr > SEVERE)
  63.             return NORMAL;
  64.         }
  65.  
  66.     variantPtr = tablePtr->variantPtr;
  67.  
  68.     switch (size)
  69.         {
  70.         case 0:                 /* no immediate operand */
  71.             if (pass2)
  72.                 {
  73.                 output( (long) variantPtr->bytemask, WORD);
  74.                 noOperand = TRUE;
  75.                 }
  76.             loc += 2;
  77.             break;
  78.         case WORD:                      /* 16-bit immediate operand */
  79.             op = opParse(op, &source, errorPtr);
  80.             if (*errorPtr > SEVERE)
  81.                 return NORMAL;
  82.             if (source.mode != Immediate)
  83.                 {
  84.                 NEWERROR(*errorPtr, INV_ADDR_MODE);
  85.                 return NULL;
  86.                 }
  87.             if (!isspace(*op) && *op != '\0')
  88.                                     /* if operand field contains
  89.                                      * superfluous characters */
  90.                 {
  91.                 NEWERROR(*errorPtr, SYNTAX);
  92.                 return NORMAL;
  93.                 }
  94.             if (pass2)
  95.                 output( (long) variantPtr->wordmask, WORD);
  96.             loc += 2;
  97.             if (pass2)
  98.                 {
  99.                 output( (long) (source.data & 0xffff), WORD);
  100.                 if (source.data < -32768 || source.data > 32767)
  101.                     NEWERROR(*errorPtr, INV_16_BIT_DATA);
  102.                 }
  103.             loc += 2;
  104.             break;
  105.         case LONG:                      /* 32-bit immediate operand */
  106.             op = opParse(op, &source, errorPtr);
  107.             if (*errorPtr > SEVERE)
  108.                 return NORMAL;
  109.             if (source.mode != Immediate)
  110.                 {
  111.                 NEWERROR(*errorPtr, INV_ADDR_MODE);
  112.                 return NULL;
  113.                 }
  114.             if (!isspace(*op) && *op != '\0')
  115.                                     /* if operand field contains
  116.                                      * superfluous characters */
  117.                 {
  118.                 NEWERROR(*errorPtr, SYNTAX);
  119.                 return NORMAL;
  120.                 }
  121.             if (pass2)
  122.                 output( (long) variantPtr->longmask, WORD);
  123.             loc += 2;
  124.             if (pass2)
  125.                 {
  126.                 output( (long) source.data, LONG);
  127.                 if (source.data >= -32768 && source.data <= 32767)
  128.                     NEWERROR(*errorPtr, EXCESSIVE_SIZE);
  129.                 }
  130.             loc += 4;
  131.             break;
  132.         default:
  133.             NEWERROR(*errorPtr, INV_SIZE_CODE);
  134.             break;
  135.         }
  136.     return NORMAL;
  137.     }
  138.  
  139.  
  140.  
  141.