/*************************************************************/ /* proj4.c This file consists of two parts. a. data structures of code storage b. emit functions */ /**************** data structures *******************/ #define DATA_LINE_MAX 500 /* # of lines in data definition */ #define CODE_LINE_MAX 8000 /* # of lines in code */ #define DATA_MAX 10000 /* # of chars in data definition */ #define CODE_MAX 100000 /* # of chars in code */ typedef struct { int mode; /* operand mode, see definitions below */ int num_const; /* number constant or the offset in register displayment mode */ char char_const; /* char constant */ char *ident; /* identifier */ int reg; /* register number */ } OPERAND; /* operand mode */ #define NUM_CONST 50 /* operand is a number constant */ #define CHAR_CONST 60 /* char constant */ #define IDENTIFIER 70 /* operand is an identifier */ #define REGISTER 80 /* operand is in a register */ #define REG_DEFER 90 /* the address of operand is the content of a reg */ #define REG_DISPL 100 /* the address of operand is the content of a reg + a number */ /* register definition */ #define R0 0 #define R1 1 #define R2 2 #define R3 3 #define R4 4 #define R5 5 #define R6 6 #define R7 7 #define R8 8 #define R9 9 #define R10 10 #define R11 11 #define AP 12 #define FP 13 #define SP 14 #define PC 15 /* instruction definition */ /* general group */ #define ADD 21 #define SUB 22 #define MUL 23 #define DIV 24 #define AND 25 #define OR 26 #define MOV 27 #define MOVA 28 #define PUSH 29 #define PUSHA 30 #define CMP 31 #define TST 32 /* brach and jump group */ #define BEQL 40 #define BGEQ 41 #define BGTR 42 #define BLEQ 43 #define BLSS 44 #define BNEQ 45 #define JMP 46