- 1、本文档共4页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
cpuled计算机组成实验
module alu(s,sel,cin,wt,d,f,cout,x,y,clk);
input sel,wt,cin,clk;
input [2:0] s;
input [7:0] d;
output reg [7:0] f,y;
output reg [2:0] x;
output cout;
reg [7:0] a,b;
initial
begin
a=0;
b=0;
end
always @(posedge clk)
begin
if(sel==1wt==1) a=d;
else if(sel==1wt==0) b=d;
case(s)
3b000:f=0;
3b001:f=ab;
3b010:f=a|b;
3b011:f=a^b;
3b100:{cout,f}=a+b+cin;
3b101:f=a1;
3b110:f=a1;
3b111:f=8hzz;
endcase
end
always @(posedge clk)
begin
x=3b000;
xianshi(x,f[7:4]);
x=3b001;
xianshi(x,f[3:0]);
end
task xianshi ;
input[2:0] ax;
input[3:0] af;
case(af[3:0])
4d0:y=8
4d1:y=8
4d2:y=8
4d3:y=8
4d4:y=8
4d5:y=8
4d6:y=8
4d7:y=8
4d8:y=8
4d9:y=8
4d10:y=8
4d11:y=8
4d12:y=8
4d13:y=8
4d14:y=8
4d15:y=8
endcase
endtask
endmodule
module cpu(d,ra,wr,rd,m,clk,clk1,reset,ale,pcl,pch,x,y);
input wr,rd,clk,reset,ale,clk1;
input [1:0] ra,m;
input [7:0] d;
output reg [7:0] pcl,pch,y;
output reg [2:0] x;
reg [7:0] r0,r1,r2,r3;
reg [15:0] pc;
initial
begin
x=0;
y=0;
pcl=0;
pch=0;
pc=0;
r3=0;
r0=0;
r1=0;
r2=0;
r3=0;
end
always@(negedge clk) //8位寄存器
begin
begin
if(wr==0rd==1)
case(ra)
2b00:r0=d;
2b01:r1=d;
2b10:r2=d;
2b11:r3=d;
endcase
else if(wr==1rd==0)
case(ra)
2b00:pcl=r0;
2b01:pcl=r1;
2b10:pcl=r2;
2b11:pcl=r3;
endcase
end
if(ale==1)pcl=pc[7:0];
pch=pc[15:8];
end
always@(negedge clk1) //16位寄存器
begin
if(reset==0)pc=0;
else
case(m)
2b00:pc[15:8]=d;
2b01:pc[7:0]=d;
2b10:pc=pc+1;
2b11:pc=pc-1;
endcase
end
always@(negedge clk)
begin
x=x+1;
if(x==0) xianshi(pch[7:4]);
else if(x==1) xianshi(pch[3:0]);
else if(x==2) xianshi(pcl[7:4]);
else if(x==3) xianshi(pcl[3:0]);
else xianshi(0);
end
task xianshi ;
input[3:0] af;
case(af[3:0])
4d0:y=8
4d1:y=8
4d2:y=8
4d3:y=8
4d4:y=8
4d5:y=8
4d6:y=8
4d7:y=
文档评论(0)