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

📄 instr_memory.h

📁 SystemC 实现 MIPS 处理器 源代码
💻 H
字号:
#ifndef INSTR_MEMORY_H
#define INSTR_MEMORY_H

#include "STDAFX.h"

//指令寄存器
SC_MODULE(Instr_Memory)
{
	//输入指令地址
	sc_in<sc_uint<32> > address;
	//输出指令
	sc_out<sc_uint<32> > instr;
 
	//指令内存
	sc_uint<32> instr_data[1024];

	//
	void entry()
	{
		//next_trigger(100,SC_NS);

		unsigned int add=address.read()/4;
		if (add>=1024) return;

		instr.write(instr_data[add]);
	}

	void Input()
	{
		cout<<"请每行输入一条指令,用unsigned int 表示。输入行为#时表示指令结束"<<endl;
		char currentInstr[1000];
		int i=0;
		unsigned int temp;
		while (true)
		{
			std::cin.getline(currentInstr,500,'\n');
			if (currentInstr[0]=='#') break;
			i++;
			if (currentInstr[0]=='=')
				sscanf(currentInstr+1,"%ud",&temp);
			else
				sscanf(currentInstr,"%ud",&temp);

			instr_data[i]=temp;
		}	
	}
	
	//构造函数
	SC_CTOR(Instr_Memory)
	{
		SC_METHOD(entry);
		sensitive<<address;

		int i;
		for (i=0;i<1024;++i) instr_data[i]=0;

	}
};

/*
//测试模块
SC_MODULE(test_Instr_Memory)
{
	sc_out<sc_uint<32> > address;
	sc_in<sc_uint<32> > instr;

	void test()
	{
		int i;

		cout<<0<<":";
		address.write(0);
		wait();
		Print(instr.read());

		cout<<1<<":";
		address.write(1);
		wait();
		Print(instr.read());
		
		cout<<2<<":";
		address.write(2);
		wait();
		Print(instr.read());
	}

	SC_CTOR(test_Instr_Memory)
	{
		SC_THREAD(test);
		sensitive<<instr;
		//dont_initialize();
	}
};

//测试函数
void test_Memory_Instruction()
{
	Instr_Memory instr_memory("Instr_Memory");
	test_Instr_Memory test("test_Instr_Memory");

	sc_signal<sc_uint<32> > address,instr;
	instr_memory.address(address);
	instr_memory.instr(instr);

	test.address(address);
	test.instr(instr);

	sc_start(100);
}

*/

#endif

⌨️ 快捷键说明

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