实验报告模板
- 格式:docx
- 大小:485.32 KB
- 文档页数:19
同济大学
计算机科学与技术系
计算机组成原理课程实验报告
学号*******
姓名冯凯
专业计算机科学与技术
授课老师王力生
日期2016.06.18
一、实验目标
1、熟悉Verilog语言的编写。
2、掌握计算机的每个部件的构成逻辑及工作原理,计算机各部件之间的连接逻辑,计算机整机的工作原理。
3、掌握CPU功能。
4、设计55条单周期指令CPU下板成功
2、.在自己的CPU上跑一个汇编程序
二、总体设计
1.作品功能设计及原理说明
module comp(
input clock,
input resetn,
output [2:0] r,
output [2:0] g,
output [1:0] b,
output hs,
output vs,
);
2.硬件逻辑图
三、主要模块设计
1.ALU
module alu(
input [31:0] a,
input [31:0] b,
input [3:0] aluc,
output [31:0] r,
output zero,//零标志
output carry, // 进位标志位
output negative, // 负数标志位
output overflow // 溢出标志位
);
wire [31:0] d_and = a&b;//0100
wire [31:0] d_or = a|b;//0101
wire [31:0] d_xor = a^b;//0110
wire [31:0] d_nor = ~(a|b);//0111
wire [31:0] d_lui = {b[15:0],16'h0};//100x
wire [31:0] d_slt = a
wire [31:0] d_sltu = (a[31]&&~b[31])||(a[31]&&b[31]&&a>b)||(~a[31]&&~b[31]&&a
wire [31:0] d_and_or = aluc[0]?d_or:d_and;
wire [31:0] d_xor_nor = aluc[0]?d_nor:d_xor;
wire [31:0] d_and_or_xor_nor = aluc[1]?d_xor_nor:d_and_or;
wire [31:0] d_slt_sltu = aluc[0]?d_slt:d_sltu;
wire [31:0] d_lui_slt_sltu = aluc[1]?d_slt_sltu:d_lui;
wire [31:0] d_as;
wire [31:0] d_sh;
wire carry_as;
wire negative_as;
wire overflow_as;
wire carry_sh;
addsub32 as32(a,b,aluc[0],aluc[1],d_as,carry_as,overflow_as);
shift shifter(b,a[4:0],~aluc[1],~aluc[0],d_sh,carry_sh);
mux4x32 select_d(d_as,d_and_or_xor_nor,d_lui_slt_sltu,d_sh,aluc[3:2],r);
mux4x1 select_carry(carry_as,1'b0,1'b0,carry_sh,aluc[3:2],carry);
mux4x1 select_overflow(overflow_as,1'b0,1'b0,overflow_sh,aluc[3:2],overflow);
assign zero = ~|r;
assign negative = r[31];
endmodule
2.regfile
module regfile(
input [4:0] raddr1,
input [4:0] raddr2,
input [31:0] wdata,
input [4:0] waddr,
input we,
input clk,
input rst,
output [31:0] radata1,
output [31:0] radata2
);
reg [31:0] register[0:31];
assign radata1=(raddr1==0)?0:register[raddr1];
assign radata2=(raddr2==0)?0:register[raddr2];
integer i;
always @ (posedge rst or negedge clk)begin
if(rst==1)
begin
for(i=1;i<32;i=i+1)begin
register[i]<=0;
end
end
else begin
register[0]<=32'b0;
if((waddr!=0)&&we)begin
register[waddr]<=wdata;
end
end
end
endmodule
3.CP0
module Coprocessor0(
input clk,
input[4:0] C0adr,
input[31:0] C0Wdata,
input C0Write,
input[31:0] InteCause,
input Interrupt,
output InteAccept,
output[31:0] C0State,
output reg[31:0] C0Data
);
parameter EPCadr = 5'h0;
parameter Causeadr = 5'h1;
parameter Stateadr = 5'h2;
reg[31:0] EPC;
reg[31:0] Cause;
reg[31:0] State;
initial begin
State <= 32'h1;
Cause <= 32'h0;