📄 instruction.cpp
字号:
/*
* Copyright (c) 2005 Zhejiang University, P.R.China
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
//=============================================================================
/**
* \file Arch/MU0/Instruction.cpp
*
* $Id: Instruction.cpp,v 1.2 2005/02/21 09:53:26 kehc Exp $
*
* \author
*/
//=============================================================================
#include "stdafx.h"
#include "./Instruction.h"
#include "./Processor.h"
namespace MU0 {
DEFINE_SINGLETON(Instruction)
DEFINE_SINGLETON(Instruction_Set)
CPU & Instruction::get_cpu(void) const
{
return (CPU&)(*cpu_);
}
void Instruction::on_LDA(int op, int operand)
{
Core::Bytecode_Type buffer;
Core::u16 val;
get_cpu().get_mmu().access(Core::Memory_16Bit::MEMORY_READ, operand, 2, buffer);
Core::Wukong_Get_System().convert_from_bytecode(buffer, val);
get_cpu().write_register(CPU::ACC, val);
}
void Instruction::on_STO(int op, int operand)
{
Core::Bytecode_Type buffer;
Core::Register_Int val;
get_cpu().read_register(CPU::ACC, val);
Core::Wukong_Get_System().convert_to_bytecode((Core::u16)val, buffer);
get_cpu().get_mmu().access(Core::Memory_16Bit::MEMORY_WRITE, operand, 2, buffer);
}
void Instruction::on_ADD(int op, int operand)
{
Core::Bytecode_Type buffer;
Core::u16 val;
Core::Register_Int old_val;
get_cpu().read_register(CPU::ACC, old_val);
get_cpu().get_mmu().access(Core::Memory_16Bit::MEMORY_READ, operand, 2, buffer);
Core::Wukong_Get_System().convert_from_bytecode(buffer, val);
get_cpu().write_register(CPU::ACC, (Core::u16)old_val + val);
}
void Instruction::on_SUB(int op, int operand)
{
Core::Bytecode_Type buffer;
Core::u16 val;
Core::Register_Int old_val;
get_cpu().read_register(CPU::ACC, old_val);
get_cpu().get_mmu().access(Core::Memory_16Bit::MEMORY_READ, operand, 2, buffer);
Core::Wukong_Get_System().convert_from_bytecode(buffer, val);
get_cpu().write_register(CPU::ACC, (Core::u16)old_val - val);
}
void Instruction::on_JMP(int op, int operand)
{
Core::Bytecode_Type buffer;
get_cpu().set_pc((Core::u16)operand);
}
void Instruction::on_JGE(int op, int operand)
{
Core::Bytecode_Type buffer;
Core::u16 val;
get_cpu().get_mmu().access(Core::Memory_16Bit::MEMORY_READ, operand, 2, buffer);
Core::Wukong_Get_System().convert_from_bytecode(buffer, val);
if (val >= 0)
{
get_cpu().set_pc((Core::u16)operand);
}
}
void Instruction::on_JNE(int op, int operand)
{
Core::Bytecode_Type buffer;
Core::u16 val;
get_cpu().get_mmu().access(Core::Memory_16Bit::MEMORY_READ, operand, 2, buffer);
Core::Wukong_Get_System().convert_from_bytecode(buffer, val);
if (val != 0)
{
get_cpu().set_pc((Core::u16)operand);
}
}
void Instruction::on_STP(int op, int operand)
{
get_cpu().stop();
}
void Instruction::execute(Core::Instruction_Unit binary)
{
Core::Binary_16Bit bits((Core::u16)binary);
int op = bits.convert_to_int(12, 15);
int operand = bits.convert_to_int(0, 11);
switch (op)
{
case LDA:
on_LDA(op, operand);
break;
case STO:
on_STO(op, operand);
break;
case ADD:
on_ADD(op, operand);
break;
case SUB:
on_SUB(op, operand);
break;
case JMP:
on_JMP(op, operand);
break;
case JGE:
on_JGE(op, operand);
break;
case JNE:
on_JNE(op, operand);
break;
case STP:
on_STP(op, operand);
break;
default:
assert(0);
break;
};
}
void Instruction_Set::register_instructions()
{
register_instruction(MU0::Instruction::instance());
}
Core::Instruction * Instruction_Set::classify(Core::Instruction_Unit binary)
{
return instructions_[0];
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -