简单cpu处理器

在135例中有一个简单处理器的程序,稍作修改成自己的风格

 1 //date :2013/8/22
 2 //designer :pengxiaoen
 3 //function get a mpc with verilog
 4 
 5 module mpc (
 6              clock,reset,
 7                  instrction,
 8                  result
 9                  );
10 input clock ,reset;
11 input [17:0] instrction;
12 output reg [8:0] result;
13 
14 reg [1:0] opreation;
15 reg [7:0] oprearand1,oprearand2;
16 
17 always @ (posedge clock  or negedge reset)
18 if(!reset)
19    begin
20        opreation <= 2'd0;
21          oprearand1 <= 8'd0;
22          oprearand2 <= 8'd0; 
23     end 
24 else {opreation ,oprearand1,oprearand2} <= instrction;    
25 
26 always @ (posedge clock or negedge reset)
27 if (!reset)
28     begin
29          result <= 9'd0; 
30      end 
31 else begin
32          case (opreation)
33                 2'b00 : begin result <= {1'b0,oprearand1}; end
34                  2'b01 : begin result <= {1'b0,oprearand2}; end
35                  2'b10 : begin result <= oprearand1 + oprearand2; end
36                  2'b11 : begin result <= oprearand1 - oprearand2; end
37                  default result <= 9'bz_zzzz_zzzz;
38            endcase     
39      end 
40 endmodule 

指令的前面2个bit 是操作码,后面的两个8bit 是操作数。
00表示结果输出为第一个操作数,01表示结果输出第二个操作数,10表示输出结果为两个操作数相加,11表示输出结果为两个操作数相减;

原文地址:https://www.cnblogs.com/sepeng/p/3275067.html