📄 instruction.h
字号:
//Instruction.h
//The name of these classes should be the same with their instrution name
//defined in the CASL
//assemble languable
//refer to CPU.H and relationship between CPU and Instruction
//Abstract Class Instruction Defination
#if !defined(AFX_INSTRUCTION1_H__2CF0D75C_780E_478C_B792_185C2C813A14__INCLUDED_)
#define AFX_INSTRUCTION1_H__2CF0D75C_780E_478C_B792_185C2C813A14__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
//declare the classes that will be used in the Instruction clss:
#include "type.h"
class CPU;
class Instruction{
protected:
CPU*_cpu;//point to the CPU that the Instruction belong to
BYTE m_bInstructionCode;
char* m_strName;//instruction name
public:
void ReportState(CString strState);
//construction/destruction
Instruction();
~Instruction();
virtual void Excute(DWORD dwCode);//excute the binary code
//different subclasses may important it differently
//must implement in Subclass
//attribute
virtual void SetCPU(CPU* lpCPU);//specity a cpu for the _cpu
virtual CPU* GetCPU();
virtual void SetinstructionCode(BYTE& bCode);
virtual BYTE GetinstructionCode();
virtual char* GetName(){return m_strName;}
};
//Subclasses of Instruction class
//A special class implement a special Instruction
//Class LD defination:
//used for loading data from memory to register
class LD:public Instruction {
public:
LD(){m_bInstructionCode=0x1;m_strName="LD";}
virtual void Excute(DWORD dwCode);
};
//Note:the argument dwCode of the fuction Excute,
//dwCode's hight 7 bits should be 0000001
//class ST defination:
//used for moving data from register to memory
class ST:public Instruction{
public:
ST(){m_bInstructionCode=0x2;m_strName="ST";}
virtual void Excute(DWORD dwCode);//the hight 7 bits of dwcode should be 0000010
};
//class LEA defination:
//used for the memory address to register
class LEA:public Instruction{
public:
LEA(){m_bInstructionCode=0x3;m_strName="LEA";}
virtual void Excute(DWORD dwCode);//the hight 7 bits of dwcode should be 0000011
};
//class ADD defination:
//used for adding Instruction
class ADD:public Instruction{
public:
ADD(){m_bInstructionCode=0x4;m_strName="ADD";}
virtual void Excute(DWORD dwCode);//the hight 7 bits of dwcode should be 0000100
};
//class SUB defination:
//used for implementing Substract Instruction
class SUB:public Instruction{
public:
SUB(){m_bInstructionCode=0x5;m_strName="SUB";}
virtual void Excute(DWORD dwCode);//the hight 7 bits of dwcode should be 0000101
};
//class ST defination:
//used for implementing shift left Algorithm Instruction
class SLA:public Instruction{
public:
SLA(){m_bInstructionCode=0x6;m_strName="SLA";}
virtual void Excute(DWORD dwCode);//the hight 7 bits of dwcode should be 0000110
};
//class SRA defination:
//used for implementing shift right Algorithm Instruction
class AND:public Instruction{
public:
AND(){m_bInstructionCode=0x7;m_strName="AND";}
virtual void Excute(DWORD dwCode);//the hight 7 bits of dwcode should be 0000111
};
//class AND defination:
//used for implementing logical"AND" Instruction
class SRA:public Instruction{
public:
SRA(){m_bInstructionCode=0x8;m_strName="SRA";}
virtual void Excute(DWORD dwCode);//the hight 7 bits of dwcode should be 0001000
};
//class OR defination:
//used for implementing logical"OR" Instruction
class OR:public Instruction{
public:
OR(){m_bInstructionCode=0x9;m_strName="OR";}
virtual void Excute(DWORD dwCode);//the hight 7 bits of dwcode should be 0001001
};
//class EOR defination:
//used for implementing logical"EOR" Instruction
class EOR:public Instruction{
public:
EOR(){m_bInstructionCode=0xA;m_strName="EOR";}
virtual void Excute(DWORD dwCode);//the hight 7 bits of dwcode should be 0001010
};
//class NOT defination:
//used for implementing logical"NOT" Instruction
class NOT:public Instruction{
public:
NOT(){m_bInstructionCode=0xB;m_strName="NOT";}
virtual void Excute(DWORD dwCode);//the hight 7 bits of dwcode should be 0001011
};
//class SLL defination:
//used for implementing Shift left logic Instruction
class SLL:public Instruction{
public:
SLL(){m_bInstructionCode=0xC;m_strName="SLL";}
virtual void Excute(DWORD dwCode);//the hight 7 bits of dwcode should be 0001100
};
//class SRL defination:
//used for implementing shift Right logic Instruction
class SRL:public Instruction{
public:
SRL(){m_bInstructionCode=0xD;m_strName="SRL";}
virtual void Excute(DWORD dwCode);//the hight 7 bits of dwcode should be 0001101
};
//class CPA defination:
//used for implementing Agorithm compare Instruction
class CPA:public Instruction{
public:
CPA(){m_bInstructionCode=0xE;m_strName="CPA";}
virtual void Excute(DWORD dwCode);//the hight 7 bits of dwcode should be 0001110
};
//class CPL defination:
//used for implementing logical compare Instruction
class CPL:public Instruction{
public:
CPL(){m_bInstructionCode=0xF;m_strName="CPL";}
virtual void Excute(DWORD dwCode);//the hight 7 bits of dwcode should be 0001111
};
//class JMP defination:
class JMP:public Instruction{
public:
JMP(){m_bInstructionCode=0x10;m_strName="JMP";}
virtual void Excute(DWORD dwCode);//the hight 7 bits of dwcode should be 0010000
};
//class JPZ defination:
class JPZ:public Instruction{
public:
JPZ(){m_bInstructionCode=0x11;m_strName="JPZ";}
virtual void Excute(DWORD dwCode);//the hight 7 bits of dwcode should be 0010001
};
//class JMI defination:
class JMI:public Instruction{
public:
JMI(){m_bInstructionCode=0x12;m_strName="JMI";}
virtual void Excute(DWORD dwCode);//the hight 7 bits of dwcode should be 0010010
};
//class JNZ defination:
class JNZ:public Instruction{
public:
JNZ(){m_bInstructionCode=0x13;m_strName="JNZ";}
virtual void Excute(DWORD dwCode);//the hight 7 bits of dwcode should be 0010011
};
//class JZE defination:
class JZE:public Instruction{
public:
JZE(){m_bInstructionCode=0x14;m_strName="JZE";}
virtual void Excute(DWORD dwCode);//the hight 7 bits of dwcode should be 0010100
};
//class PUSH defination:
class PUSH:public Instruction{
public:
PUSH(){m_bInstructionCode=0x15;m_strName="PUSH";}
virtual void Excute(DWORD dwCode);//the hight 7 bits of dwcode should be 0010101
};
//class POP defination:
class POP:public Instruction{
public:
POP(){m_bInstructionCode=0x16;m_strName="POP";}
virtual void Excute(DWORD dwCode);//the hight 7 bits of dwcode should be 0010110
};
//class CALL defination:
class CALL:public Instruction{
public:
CALL(){m_bInstructionCode=0x17;m_strName="CALL";}
virtual void Excute(DWORD dwCode);//the hight 7 bits of dwcode should be 0010111
};
//class RET defination:
class RET:public Instruction{
public:
RET(){m_bInstructionCode=0x18;m_strName="RET";}
virtual void Excute(DWORD dwCode);//the hight 7 bits of dwcode should be 0011000
};
//class IN defination:
class INPORT:public Instruction{
public:
INPORT(){m_bInstructionCode=0x19;m_strName="INPORT";}
virtual void Excute(DWORD dwCode);//the hight 7 bits of dwcode should be 0011001
};
//class OUT defination:
class OUTPORT:public Instruction{
public:
OUTPORT(){m_bInstructionCode=0x1A;m_strName="OUTPORT";}
virtual void Excute(DWORD dwCode);//the hight 7 bits of dwcode should be 0011010
};
//class EXIT defination:
class EXIT:public Instruction{
public:
EXIT(){m_bInstructionCode=0x1B;m_strName="EXIT";}
virtual void Excute(DWORD dwCode);//the hight 7 bits of dwcode should be 0011011
};
//class INTR defination
//used for interrupting
class INTR:public Instruction{
public:
INTR(){m_bInstructionCode=0X1C;m_strName="INTR";}
virtual void Excute(DWORD dwCode);
};
//class IRET defination
//used for returning from the interrupt
class IRET:public Instruction{
public:
IRET(){m_bInstructionCode=0X1D;m_strName="IRET";}
virtual void Excute(DWORD dwCode);
};
//class STI defination
//used for set the IF flags
class STI:public Instruction{
public:
STI(){m_bInstructionCode=0X1E;m_strName="STI";}
virtual void Excute(DWORD dwCode);
};
//class CLI defination
//used fot clear the IF flags
class CLI:public Instruction{
public:
CLI(){m_bInstructionCode=0X1F;m_strName="CLI";}
virtual void Excute(DWORD dwCode);
};
#endif // !defined(AFX_INSTRUCTION1_H__2CF0D75C_780E_478C_B792_185C2C813A14__INCLUDED_)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -