4.3 Generate Object Code

The following program generates the object code of the text section.

struct mnemonic *mnm;
unsigned char *obj_code;

switch (mnm->mnm_type)
{
  case LDUB:
  case LDSB:
  case LDUH:
  case LDSH:
  case LD:
  case LDD:
  case SWAP:
  {
    if (mnm->format == 2)
    {
      f30 = (struct format30 *)(obj_code + location_counter);
      init_format30 (f30, mnm->mnm_type);
      f30->rs1 = register_to_unsignedint (mnm->u[0].reg);
      f30->rs2 = register_to_unsignedint (mnm->u[1].reg);
      f30->rd = register_to_unsignedint (mnm->u[2].reg);
    }
    else if (mnm->format == 3)
    {
      f31 = (struct format31 *)(obj_code + location_counter);
      init_format31 (f31, mnm->mnm_type);
      f31->rs1 = register_to_unsignedint (mnm->u[0].reg);
      f31->simm13 = expression_result (mnm->u[1].exp);
      f31->rd = register_to_unsignedint (mnm->u[2].reg);
    }
    ...... (other formats)
  } //end of case LDUB:
  ...... (other mnemonic types)
} //end of switch (mnm->mnm_type)

table of content