Exemplo n.º 1
0
/*
 * Executes a given instruction, or errors out
 * ins - instruction to run
 */
void
execute (unsigned short int ins)
{
    /* seperate instruction into parts */
    short int a0 = (ins >> 12) % 16;
    short int a1 = (ins >> 8) % 16;
    short int a2 = (ins >> 4) % 16;
    short int a3 = (ins >> 0) % 16;

    /* Run associated instruction */
    switch(a0) {
    case 0x0:
        _add (a1, a2, a3);
        break;
    case 0x1:
        _sub (a1, a2, a3);
        break;
    case 0x2:
        _mul (a1, a2, a3);
        break;
    case 0x3:
        _div (a1, a2, a3);
        break;
    case 0x6:
        _beq (a1, a2, a3);
        break;
    case 0x7:
        _bgt (a1, a2, a3);
        break;
    case 0x8:
        _ld (a1, a2, a3);
        break;
    case 0x9:
        _st (a1, a2, a3);
        break;
    case 0xa:
        _lc (a1, a3);
        break;
    case 0xb:
        _jmp (a1, a3);
        break;
    case 0xc:
        _inc (a1, a3);
        break;
    case 0xf:
        _sys (a1, a3);
        break;
    default:
        printf ("Error: invalid opcode %#x.\n", a0);
        sys_dump (0x0);
        sys_halt (0x0);
    }
}
Exemplo n.º 2
0
void VMDriver::execute(){
	if( this->m_state == STATE_IDLE ){
		printf( "Error: state is idle. \n");
		return;
	}

	assert( this->currentAssembly() );
	while( this->isActive() ){
		if( this->isBreak() ){
			break;
		}
		unsigned char content = this->getByte( m_funcAddr , m_pc );
		m_pc++;
		switch( content ){
			case EMnemonic::MovPtr :
				_mov_ptr();
				break;
			case EMnemonic::Mov :
				_mov();
				break;
			case EMnemonic::Add :
				_add();
				break;
			case EMnemonic::Sub :
				_sub();
				break;
			case EMnemonic::Mul :
				_mul();
				break;
			case EMnemonic::Div :
				_div();
				break;
			case EMnemonic::Rem :
				_rem();
				break;
			case EMnemonic::Inc :
				_inc();
				break;
			case EMnemonic::Dec :
				_dec();
				break;
			case EMnemonic::Push :
				_push();
				break;
			case EMnemonic::PushPtr :
				_push_ptr();
				break;
			case EMnemonic::Pop :
				_pop();
				break;
			case EMnemonic::Call :
				_call();
				break;
			case EMnemonic::ST :
				_st();
				break;
			case EMnemonic::LD :
				_ld();
				break;
			case EMnemonic::EndFunc :
				_endFunc();
				break;

			case EMnemonic::CmpGeq : 
			case EMnemonic::CmpG :
			case EMnemonic::CmpLeq : 
			case EMnemonic::CmpL :
			case EMnemonic::CmpEq : 
			case EMnemonic::CmpNEq :
				_cmp( content );
				break;
			case EMnemonic::Not :
				_not();
				break;
			case EMnemonic::Minus :
				_minus();
				break;
			case EMnemonic::LogOr :
			case EMnemonic::LogAnd :
				_log( content );
				break;
			case EMnemonic::Jmp :
				_jmp();
				break;
			case EMnemonic::JumpZero :
				_jumpzero();
				break;
			case EMnemonic::JumpNotZero :
				_jumpnotzero();
				break;
			case EMnemonic::RET :
				_ret();
				break;
		}
	}
}