Exemplo n.º 1
0
void node_parse_line(Node *n, InputCode *ic, const char *s) {
  assert(n);
  assert(s);
  assert(strlen(s) > 2);

  char ins[4];
  strncpy(ins, s, 3);
  ins[3] = '\0';

  if (strcmp(ins, "MOV") == 0) {
    parse_mov(n, s);
  } else if (strcmp(ins, "SUB") == 0) {
    parse_onearg(n, ic, s, SUB);
  } else if (strcmp(ins, "ADD") == 0) {
    parse_onearg(n, ic, s, ADD);
  } else if (strcmp(ins, "JEZ") == 0) {
    parse_onearg(n, ic, s, JEZ);
  } else if (strcmp(ins, "JMP") == 0) {
    parse_onearg(n, ic, s, JMP);
  } else if (strcmp(ins, "JNZ") == 0) {
    parse_onearg(n, ic, s, JNZ);
  } else if (strcmp(ins, "JGZ") == 0) {
    parse_onearg(n, ic, s, JGZ);
  } else if (strcmp(ins, "JLZ") == 0) {
    parse_onearg(n, ic, s, JLZ);
  } else if (strcmp(ins, "JRO") == 0) {
    parse_onearg(n, ic, s, JRO);
  } else if (strcmp(ins, "SAV") == 0) {
    node_create_instruction(n, SAV);
  } else if (strcmp(ins, "SWP") == 0) {
    node_create_instruction(n, SWP);
  } else if (strcmp(ins, "NOP") == 0) {
    node_create_instruction(n, NOP);
  } else if (strcmp(ins, "NEG") == 0) {
    node_create_instruction(n, NEG);
  } else if (strcmp(ins, "OUT") == 0) {
    node_create_instruction(n, OUT);
  } else {
    raise_error("Don't understand instruction [%s]", ins);
  }
}
Exemplo n.º 2
0
Arquivo: 7a.c Projeto: 7shi/Betelgeuse
void assemble_pop(enum POp pop)
{
    switch (pop)
    {
    case Mov:
        parse_mov();
        break;
    case Nop:
        assemble_opr(Bis, Zero, Zero, Zero);
        break;
    case Clr:
        {
            enum Regs rc;
            if (read_reg(&rc, 0))
                assemble_opr(Bis, Zero, Zero, rc);
            break;
        }
    case Sextl:
    case Not:
    case Negl:
    case Negl__v:
    case Negq:
    case Negq__v:
        parse_opr_2(popcodes[(int)pop], Zero);
        break;
    case Fnop:
        assemble_fp(Cpys, Zero, Zero, Zero);
        break;
    case Fclr:
        {
            enum Regs fc;
            if (read_reg(&fc, 0))
                assemble_fp(Cpys, Zero, Zero, fc);
            break;
        }
    case Fabs:
    case Negf:
    case Negf__s:
    case Negg:
    case Negg__s:
    case Negs:
    case Negs__su:
    case Negs__sui:
    case Negt:
    case Negt__su:
    case Negt__sui:
        {
            enum Regs fb, fc;
            if (read_reg(&fb, 0) && read_sign(",") && read_reg(&fc, 0))
                assemble_fp(popcodes[(int)pop], Zero, fb, fc);
            break;
        }
    case Fmov:
    case Fneg:
        {
            enum Regs fb, fc;
            if (read_reg(&fb, 0) && read_sign(",") && read_reg(&fc, 0))
                assemble_fp(popcodes[(int)pop], fb, fb, fc);
            break;
        }
    }
}