单周期CPU设计(一)控制模块(minisys)(verilog)(vivado)

`timescale 1ns / 1ps
//
module control32 (
    input	[5:0]   Opcode,				// 来自取指单元instruction[31..26]
    input   [21:0]  Alu_resultHigh,
    input	[5:0]   Function_opcode,	// 来自取指单元r-类型 instructions[5..0]
    output			Jrn,				// 为1表明当前指令是jr
    output			RegDST,				// 为1表明目的寄存器是rd,否则目的寄存器是rt
    output			ALUSrc,				// 为1表明第二个操作数是立即数(beq,bne除外)
    output			MemorIOtoReg,			// 为1表明需要从存储器读数据到寄存器
    output			RegWrite,			// 为1表明该指令需要写寄存器
    output			MemWrite,			// 为1表明该指令需要写存储器
    output			Branch,				// 为1表明是Beq指令
    output			nBranch,			// 为1表明是Bne指令
    output			Jmp,				// 为1表明是J指令
    output			Jal,				// 为1表明是Jal指令
    output			I_format,			// 为1表明该指令是除beq,bne,LW,SW之外的其他I-类型指令
    output			Sftmd,				// 为1表明是移位指令
    output	[1:0]	ALUOp,				// 是R-类型或I_format=1时位1为1, beq、bne指令则位0为1
    output MemRead, // 为 1 表名是存储器读
    output IORead, // 为 1 表明是 I/O 读
    output IOWrite // 为 1 表明是 I/O 写
);
   
    wire R_format;		// 为1表示是R-类型指令
    wire Lw;			// 为1表示是lw指令
    wire Sw;			// 为1表示是sw指令

    

     assign R_format = (Opcode==6'b000000)? 1'b1:1'b0;        //--00h 
        assign RegDST = R_format;                               //说明目标是rd,否则是rt
        
        assign I_format = (Opcode>=6'b001000&&Opcode<=6'b001111); //addi+addiu+andi+ori+xori+lui+slti+sltiu
        assign Lw = (Opcode==6'b100011)? 1'b1:1'b0; //lw op100011
        assign  Jal = (Opcode==6'b000011)? 1'b1:1'b0; //jal op000011
        assign Jrn = R_format&&(Function_opcode==6'b001000); //jr op000000 func001000
        
        assign Sw = (Opcode==6'b101011)? 1'b1:1'b0; //sw op101011
        assign ALUSrc = I_format||Sw||Lw;  //除了beq,bne的I类型指令
        assign Branch = (Opcode==6'b000100)? 1'b1:1'b0; //beq op000100
        assign nBranch = (Opcode==6'b000101)? 1'b1:1'b0; //bne op000101
        assign Jmp = (Opcode==6'b000010)? 1'b1:1'b0; //j op000010 
        //assign MemtoReg = Lw;
        assign Sftmd = R_format&&Function_opcode[5]==0&&!Jrn; //sftmd=sll+srl+sra+sllv+srlv+srav
        
        assign RegWrite = I_format||Lw||Jal||(R_format&&!Jrn);//I_format=1,Lw,Jar或者R_format排除jr,RegWrite=1
        assign MemWrite = ((Sw==1)&&(Alu_resultHigh[21:0] !=
                                 22'b1111111111111111111111))? 1'b1:1'b0;//写存储器
        assign MemRead = ((Lw==1)&&(Alu_resultHigh[21:0] !=
                         22'b1111111111111111111111))? 1'b1:1'b0;//读存储器
        assign IOWrite = ((Sw==1)&&(Alu_resultHigh[21:0] ==          
                         22'b1111111111111111111111))? 1'b1:1'b0;//写端口
        assign IORead = ((Lw==1)&&(Alu_resultHigh[21:0] ==       
                         22'b1111111111111111111111))? 1'b1:1'b0;//读端口
        assign MemorIOtoReg = (MemRead||IORead);
        
        assign ALUOp = {(R_format||I_format),(Branch||nBranch)};//位拼接
    
    endmodule

仿真文件如下

`timescale 1ns / 1ps
//
// Company: 
// Engineer: 
// 
// Create Date: 2016/07/28 21:56:12
// Design Name: 
// Module Name: control32_sim
// Project Name: 
// Target Devices: 
// Tool Versions: 
// Description: 
// 
// Dependencies: 
// 
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
// 
//


module control32_sim(
    );
        // input
        reg[5:0]   Opcode = 6'b000000;            // 来自取指单元instruction[31..26]
        reg[5:0]   Function_opcode  = 6'b100000;      // r-form instructions[5..0]  //ADD
        // output
        wire       Jrn;
        wire       RegDST;
        wire       ALUSrc;            // 决定第二个操作数是寄存器还是立即数
        wire       MemtoReg;
        wire       RegWrite;
        wire       MemWrite;
        wire       Branch;
        wire       nBranch;
        wire       Jmp;
        wire       Jal;
        wire       I_format;
        wire       Sftmd;
        wire[1:0]  ALUOp;
        
     control32  Uctrl(
        .Opcode     (Opcode),	     // 来自取指单元instruction[31..26]
        .Function_opcode(Function_opcode),	// 来自取指单元r-类型 instructions[5..0]
        .Jrn             (Jrn),				// 为1表明当前指令是jr
        .RegDST     (RegDST),	// 为1表明目的寄存器是rd,否则目的寄存器是rt
        .ALUSrc     (ALUSrc),		// 为1表明第二个操作数是立即数(beq,bne除外)
        .MemtoReg(MemtoReg),	// 为1表明需要从存储器读数据到寄存器
        .RegWrite   (RegWrite),	// 为1表明该指令需要写寄存器
        .MemWrite   (MemWrite),	// 为1表明该指令需要写存储器
        .Branch         (Branch),		// 为1表明是Beq指令
        .nBranch       (nBranch),	// 为1表明是Bne指令
        .Jmp              (Jmp),			// 为1表明是J指令
        .Jal                (Jal),			// 为1表明是Jal指令
        .I_format       (I_format),			// 为1表明该指令是除beq,bne,LW,SW之外的其他I-类型指令
        .Sftmd          (Sftmd),				// 为1表明是移位指令
        .ALUOp	    (ALUOp)			// 是R-类型或I_format=1时位1为1, beq、bne指令则位0为1
);
                     
    initial begin
        #200     Function_opcode  = 6'b001000;               // JR
        #200    Opcode = 6'b001000;                         //  ADDI
        #200    Opcode = 6'b100011;                         //  LW
        #200    Opcode = 6'b101011;                         //  SW
        #250    Opcode = 6'b000100;                         //  BEQ
        #200    Opcode = 6'b000101;                         //  BNE
        #250    Opcode = 6'b000010;                         //  JMP
        #200    Opcode = 6'b000011;                         //  JAL
        #250    begin Opcode = 6'b000000; Function_opcode  = 6'b000010; end;//  SRL
    end         
endmodule

仿真波形图如下图所示

 

 

  • 5
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值