9 struct symbol_hash symbol_hash
[HASH_SIZE
];
14 void inc_rom_address()
32 printf("---------- HASH TABLE ----------\n");
33 printf("Position\tAdd\tName\n");
36 if(symbol_hash
[i
].name
[0] != '\0')
38 printf("HASH: %d\t%d\t%s\n", i
, symbol_hash
[i
].address
, symbol_hash
[i
].name
);
44 int hash(char symbol
[])
48 while(symbol
[i
] != '\0')
53 hash
= hash
% HASH_SIZE
;
57 int add_entry(char symbol
[], int address
)
60 hash_val
= hash(symbol
);
61 if(symbol_hash
[hash_val
].name
[0] == '\0') /* no entry at this location yet */
63 strcpy(symbol_hash
[hash_val
].name
, symbol
);
66 symbol_hash
[hash_val
].address
= ram_address
++;
68 symbol_hash
[hash_val
].address
= address
;
71 } else { /* hash alreay used */
73 /* compare value of symbol here with input of function */
74 /* this could be a repeat hash */
75 if(strcmp(symbol_hash
[hash_val
].name
, symbol
) == 0) { return 1; }
77 if(next_hash_space() != -1)
79 strcpy(symbol_hash
[hash_val
].name
, symbol
);
82 symbol_hash
[hash_val
].address
= ram_address
++;
84 symbol_hash
[hash_val
].address
= address
;
89 int i
= find_line_num();
91 exit_error(13, "Symbol table full");
103 } while (symbol_hash
[i
].name
[0] != '\0' && i
< HASH_SIZE
);
105 if(symbol_hash
[i
].name
[0] == '\0')
113 int get_address(char symbol
[])
115 int hash_val
, i
= 0, j
= 0;
116 hash_val
= hash(symbol
);
117 if(symbol_hash
[hash_val
].name
!= NULL
)
119 return symbol_hash
[hash_val
].address
;
122 could not find hash -- loop through strings
123 for length of symbol_hash looking for a match
125 while(strcmp(symbol_hash
[i
].name
, symbol
) != 0 && j
< HASH_SIZE
)
127 if(i
== HASH_SIZE
){ i
= 0; } else { ++i
; }
130 if(strcmp(symbol_hash
[i
].name
, symbol
) == 0)
132 return symbol_hash
[i
].address
;