⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dlxdoc.h

📁 计算机体系结构中,关于DLXS的模拟程序.在vc6.0下编译通过.
💻 H
字号:
// DlxDoc.h : interface of the CDlxDoc class
//
/////////////////////////////////////////////////////////////////////////////

#if !defined(AFX_DLXDOC_H__077322C4_D12E_4C76_B634_59965D22EC33__INCLUDED_)
#define AFX_DLXDOC_H__077322C4_D12E_4C76_B634_59965D22EC33__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

typedef enum{LW,SW,ADD,SUB,MUT,DIV,AND,OR,XOR,ADDI,SUBI,
MUTI,DIVI,ANDI,ORI,XORI,BEQZ,BNEZ,J,JR,TRAP,UNKNOWN}Tokentype;

typedef struct 
{
	char name[5];
	Tokentype tok;
}Operation;

Tokentype Lookup(const char * name); 

//指令的一般格式:
// OP DEST,SRC1,SRC2
class Instruction
{
public:
	Instruction() :state(_S_STALL),period(1),exetimes(0),pc(0),val0(0),val1(0),val2(0)
	{
		this->op = "";
		this->dest = "";
		this->src1 = "";
		this->src2 = "";
		for(int i=0; i<5; i++)
			this->forward[i][0] = this->forward[i][1] = CSize(0,0);
		for(i =0; i<MAXCLOCK; i++)
			this->states[i] = _S_STALL;
	}
public:
	// 模拟ALU中的临时寄存器
	int val0;					//保存数据结果
	int val1;					//数据源1
	int val2;					//数据源2

	int pc;						//指令在内存中的中地址
	int states[MAXCLOCK];       //指令执行过程中经历的状态集
	int state;					//当前时钟下的状态
	int outstate;				//指令得到结果的状态
	int exetimes;				
	int period;					//执行状态时钟周期数

	CString cmdString;			//存放指令的字符串

	//指令的基本格式组成部分							
	CString op;
	CString dest;
	CString src1;
	CString src2;
	
	//用于实现FORWDING
	CSize forward[5][2];//	五个周期,两种数据源val1,val2
};

class CDlxDoc : public CDocument
{
protected: // create from serialization only
	CDlxDoc();
	DECLARE_DYNCREATE(CDlxDoc)

// Attributes
private:
	UINT m_DivPeriod;
	UINT m_MulPeriod;
	int m_InstructionNum;
	UINT m_Forwarding;
	UINT m_Branch;

public:
	int m_Register[MAXREGS];
	int m_Memory[MAXMEM];
	CString m_CodeMemory[MAXMEM];
	CString m_CmdString[MAXINSTR];
	Instruction m_OneInstruction;
	Instruction m_Instruction[MAXPC];
// Operations
public:	
	CString dtob(int d,int count);
	int btod(CString b);
	int  power(int base,int n);
	void UpdateListBar(int whichList);
	void SetInstruction(int i);
	CString DisCompileInstruction(int pcnum);
	void CompileInstrunction();
	void InstructionExe(int i, int src1, int src2,int choice);
	void SetDivPeriod(UINT num) {m_DivPeriod = num;}
	void SetMulPeriod(UINT num) {m_MulPeriod = num;}
	void SetInstructionNum(int num) {m_InstructionNum = num;}
	void SetForwarding(UINT nID) {m_Forwarding = nID;}
	void SetBranch(UINT nID) {m_Branch = nID;}
	UINT GetDivPeriod() { return m_DivPeriod; }
	UINT GetMulPeriod() { return m_MulPeriod; }
	int  GetInstructionNum() { return m_InstructionNum; }
	UINT GetForwarding() { return m_Forwarding; }
	UINT GetBranch() { return m_Branch; }
// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CDlxDoc)
	public:
	virtual BOOL OnNewDocument();
	virtual void Serialize(CArchive& ar);
	virtual BOOL OnOpenDocument(LPCTSTR lpszPathName);
	//}}AFX_VIRTUAL

// Implementation
public:
	int m_Pc;					//当前pc值	
	int m_Clock;				//当前的时钟周期
	int m_CurInstr;				//当前执行指令条数
	virtual ~CDlxDoc();
#ifdef _DEBUG
	virtual void AssertValid() const;
	virtual void Dump(CDumpContext& dc) const;
#endif

protected:

// Generated message map functions
protected:
	//{{AFX_MSG(CDlxDoc)
	afx_msg void OnSetPeriod();
	afx_msg void OnExeRunStep();
	afx_msg void OnSetFwd(UINT nID);
	afx_msg void OnSetBranch(UINT nID);
	afx_msg void OnUpdateFwd(CCmdUI* pCmdUI);
	afx_msg void OnUpdateBranch(CCmdUI* pCmdUI);
	afx_msg void OnExeReset();
	afx_msg void OnSetMem();
	afx_msg void OnSetReg();
	afx_msg void OnSave();
	afx_msg void OnIdReset();
	afx_msg void OnIdComple();
	afx_msg void OnIdRun();
	afx_msg void OnSetCodemem();
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_DLXDOC_H__077322C4_D12E_4C76_B634_59965D22EC33__INCLUDED_)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -