?? mux.h
字號:
#ifndef MUX_H
#define MUX_H
#include "STDAFX.h"
//32位數據二選一多路選擇器
SC_MODULE(Mux_2x32)
{
//輸入的32位數值,無符號
sc_in<sc_uint<32> > A0,A1;
//控制信號
sc_in<bool> S;
//輸出數值
sc_out<sc_uint<32> > out;
void entry()
{
if (S.read()==1)
{
out.write(A1.read());
}
else
{
out.write(A0.read());
}
}
//構造函數
SC_CTOR(Mux_2x32)
{
SC_METHOD(entry);
sensitive<<S<<A1<<A0;
}
};
//5位數據二選一多路選擇器
SC_MODULE(Mux_2x5)
{
sc_in<sc_uint<5> > A0,A1;
sc_in<bool> S;
sc_out<sc_uint<5> > out;
void entry()
{
if (S.read())
{
out.write(A1.read());
}
else
{
out.write(A0.read());
}
}
SC_CTOR(Mux_2x5)
{
SC_METHOD(entry);
sensitive<<S<<A1<<A0;
}
};
SC_MODULE(Mux_4x32)
{
sc_in<sc_uint<32> > A3,A2,A1,A0;
sc_in<sc_uint<2> > S;
sc_out<sc_uint<32> > out;
void entry()
{
if (S.read().to_uint()==0) out.write(A0);
if (S.read().to_uint()==1) out.write(A1);
if (S.read().to_uint()==2) out.write(A2);
if (S.read().to_uint()==3) out.write(A3);
}
SC_CTOR(Mux_4x32)
{
SC_METHOD(entry);
sensitive<<A3<<A2<<A1<<A0<<S;
}
};
SC_MODULE(Mux_3x32)
{
sc_in<sc_uint<32> > ID_EX_data,EX_MEM_data,MEM_WB_data;
sc_in<sc_uint<2> > Forward;
sc_out<sc_uint<32> > data_out;
void entry()
{
if (Forward.read()==0) data_out.write(ID_EX_data.read());
if (Forward.read()==1) data_out.write(EX_MEM_data.read());
if (Forward.read()==2 || Forward.read()==3) data_out.write(MEM_WB_data.read());
}
SC_CTOR(Mux_3x32)
{
SC_METHOD(entry);
sensitive<<ID_EX_data<<EX_MEM_data<<MEM_WB_data<<Forward;
}
};
#endif
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -