4.1 Construct Symbol Table

The following code adds new symbols to the symbol table.

struct instruction *instr;

while (instr != NULL)
{
  switch (instr->instr_type)
  {
    case LBL:
    {
      [allocate memory for symbol_name]
      strcpy (symbol_name, instr->u.lbl);
      [allocate memory for symbol_value]
      symbol_value->st_name = 0;
      symbol_value->st_value = location_counter;
      symbol_value->st_size = 0;
      symbol_value->st_info = ELF32_ST_INFO (STB_LOCAL, STT_NOTYPE);
      symbol_value->st_other = sequence_number++;
      symbol_value->st_shndx = section_index;
      Table_put (symbol_table, symbol_name, symbol_value);
      break;
    } //end of case LBL:
    ...... (other instruction types)
  } //end of switch (instr->instr_type)
  instr = instr->next;
}

table of content