home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 1 / crawlyvol1.bin / program / compiler / sozobon / scsrc20 / top / inst.h < prev    next >
C/C++ Source or Header  |  1991-02-22  |  3KB  |  115 lines

  1. /* Copyright (c) 1988,1991 by Sozobon, Limited.  Author: Tony Andrews
  2.  *
  3.  * Permission is granted to anyone to use this software for any purpose
  4.  * on any computer system, and to redistribute it freely, with the
  5.  * following restrictions:
  6.  * 1) No charge may be made other than reasonable charges for reproduction.
  7.  * 2) Modified versions must be clearly marked as such.
  8.  * 3) The authors are not responsible for any harmful consequences
  9.  *    of using this software, even if they result from defects in it.
  10.  */
  11.  
  12. /*
  13.  * Misc. define's, etc. for instruction parsing.
  14.  */
  15.  
  16. struct    opnd {
  17.     unsigned char    amode;    /* addressing mode used */
  18.     unsigned char    areg;    /* primary register */
  19.     unsigned char    ireg;    /* index register, if applicable */
  20.     union {
  21.         long    i_disp;        /* also used for immediate data */
  22.         char    *i_astr;    /* pointer to any symbol present */
  23.     } i_data;
  24. };
  25. #define    disp    i_data.i_disp
  26. #define    astr    i_data.i_astr
  27.  
  28. /*
  29.  * is_astr(m)    macro to determine, based on the amode field, whether
  30.  *        the 'astr' field of the structure is active.
  31.  */
  32. #define    is_astr(m)    (((m) == ABS) || ((m) == (IMM|SYMB)))
  33.  
  34. /*
  35.  * Addressing modes (in 'amode')
  36.  */
  37. #define    NONE    0        /* operand unused */
  38. #define    REG    1        /* register direct */
  39. #define    IMM    2        /* immediate */
  40. #define    ABS    3        /* absolute */
  41. #define    REGI    4        /* reg. indirect */
  42. #define    REGID    5        /* reg. indirect, w/ displacement */
  43. #define    REGIDX    6        /* reg. indirect, w/ displacement & index */
  44. #define    PCD    7        /* PC relative, w/ displacement */
  45. #define    PCDX    8        /* PC relative, w/ displacement & index */
  46.  
  47. #define    XLONG    0x10        /* long index register used */
  48. #define    SYMB    0x20        /* symbol used, not constant */
  49. #define    INC    0x40        /* auto-increment */
  50. #define    DEC    0x80        /* auto-decrement */
  51.  
  52. #define    MMASK    0x0f        /* mode mask */
  53. #define    FMASK    0xf0        /* flag mask */
  54.  
  55. #define    M(x)    ((x) & MMASK)
  56. #define    F(x)    ((x) & FMASK)
  57.  
  58. /*
  59.  * Registers
  60.  */
  61.  
  62. #define    FIRSTREG    0
  63. #define    A0    0
  64. #define    A1    1
  65. #define    A2    2
  66. #define    A3    3
  67. #define    A4    4
  68. #define    A5    5
  69. #define    A6    6
  70. #define    A7    7
  71. #define    SP    7    /* alias for A7 */
  72. #define    D0    8
  73. #define    D1    9
  74. #define    D2    10
  75. #define    D3    11
  76. #define    D4    12
  77. #define    D5    13
  78. #define    D6    14
  79. #define    D7    15
  80. #define    LASTREG    15
  81.  
  82. #define    ISD(x)    ((x) >= D0 && (x) <= D7)    /* is 'x' a  D reg. */
  83. #define    ISA(x)    ((x) >= A0 && (x) <= A7)    /* is 'x' an A reg. */
  84. #define    RM(x)    (1 << (x))            /* form a register mask */
  85.  
  86. /*
  87.  * DOK(x) - evaluates TRUE if 'x' is okay for a displacement value.
  88.  *
  89.  * 'x' must be of type "long"
  90.  */
  91. #define    DOK(x)    (((x) >= -32768L) && ((x) <= 32767L))
  92.  
  93. /*
  94.  * D8OK(x) - like DOK but for 8-bit displacements
  95.  */
  96. #define    D8OK(x)    (((x) >= -128) && ((x) <= 127))
  97.  
  98. struct    inst {
  99.     char    opcode;            /* type of instruction */
  100.     char    flags;            /* length, etc. */
  101.     struct    opnd    src, dst;    /* optional operands */
  102.     int    rref, rset;
  103.     int    live;            /* regs. live after this inst. */
  104.     struct    inst    *next;
  105.     struct    inst    *prev;
  106. };
  107.  
  108. /*
  109.  * Instruction flags
  110.  */
  111.  
  112. #define    LENB    0x01
  113. #define    LENW    0x02
  114. #define    LENL    0x04
  115.