#include #include #include "input.h" #include "output.h" #define MAX_HASHTABLE_SIZE 64 //global variable definitions char *infile_name; Table_T symbol_table; struct section *text; struct section *data; struct section *bss; int mycmp (const void *x, const void *y) { return (strcmp ((char *)x, (char *)y)); } unsigned myhash (const void *key) { int i; unsigned int sum; sum = 0; for (i = 0; i < strlen ((char*) key); i++) { sum += *((char *)key + i); } return (sum % (MAX_HASHTABLE_SIZE-1)); } int main (int argc, char *argv[]) { /*************************** (1) process the command line ***************************/ if (argc != 2) { fprintf (stderr, "Command format: myas \n"); return (-1); } infile_name = argv[1]; if ((infile_name[strlen(infile_name)-2] != '.') || (infile_name[strlen(infile_name)-1] != 's') ) { fprintf (stderr, "Input file must be .s file\n"); return (-1); } /*************************************************** (2) parse the input file into a list of instructions ***************************************************/ first = NULL; input (); /************* (3) two passes *************/ symbol_table = Table_new (0, mycmp, myhash); text = NULL; data = NULL; bss = NULL; pass1 (); //please implement this function /* print_passes(); */ pass2 (); //please implement this function /* print_passes(); */ /********************************************************** (4) write the output file in Executable and Linkable Format **********************************************************/ output (); /************** (5) free memory **************/ free_input (); free_output (); return (0); }