inline void cosmac_device::fetch_instruction() { // instruction fetch m_op = read_opcode(R[P]); R[P]++; I = m_op >> 4; N = m_op & 0x0f; m_icount -= CLOCKS_FETCH; m_state = COSMAC_STATE_1_EXECUTE; }
static int read_line(Vector v){ char op[4]; char s[10]; struct Inst inst; int res = scanf("%s %s", op, s); if(res == EOF) return 0; inst.op_code = read_opcode(op); inst.x = read_value(s); if(inst.op_code == cpy || inst.op_code == jnz){ scanf("%s", s); inst.y = read_value(s); } Vector_push(v, &inst); return 1; }
void read_instruction() { instruction_t instr = {0}; // skip empty lines if (next_token == EOL_TOKEN || next_token == EOF_TOKEN) { read_token(); return; } if (next_token == LABEL_TOKEN) { read_label(&instr.label); } else { instr.label = 0; } read_opcode(&instr.opcode); if (next_token != EOL_TOKEN) { read_argument(&instr.arg1); } if (next_token == COMMA_TOKEN) { read_token(); assert(token == COMMA_TOKEN); read_argument(&instr.arg2); } read_token(); if (token != EOL_TOKEN) { fprintf(stderr, "%s:%d: error: To much input.\n", get_scan_file(), get_scan_line()); result = -1; recover_error(); return; } add_instruction(prog, instr); }