马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
x
请问这些写的是什么东西?有什么作用?有什么错误(主要的错误和次要的错误)?然后更正~请各位大神帮帮忙。。。
- module dcpu16_alu (/*AUTOARG*/
- // Outputs
- f_dto, g_dto, rwd, regR, regO, CC,
- // Inputs
- regA, regB, opc, clk, rst, ena, pha
- );
- output [15:0] f_dto,
- g_dto,
- rwd;
-
- output [15:0] regR,
- regO;
- output CC;
-
- input [15:0] regA,
- regB;
-
- input [3:0] opc;
-
- input clk,
- rst,
- ena;
- input [1:0] pha;
- wire [15:0] src, // a
- tgt; // b
-
- /*AUTOREG*/
- // Beginning of automatic regs (for this module's undeclared outputs)
- reg CC;
- reg [15:0] regO;
- reg [15:0] regR;
- // End of automatics
- reg c;
- reg [15:0] add;
- reg [33:0] mul;
- reg [31:0] shl,
- shr;
-
- assign f_dto = regR;
- assign g_dto = regR;
- assign rwd = regR;
-
- assign src = regA;
- assign tgt = regB;
- // adder
- always @(/*AUTOSENSE*/opc or src or tgt) begin
- {c,add} <= (~opc[0]) ? (src + tgt) : (src - tgt);
- mul <= {1'b0,src} * {1'b0,tgt};
- shl <= src << tgt;
- shr <= src >> tgt;
- end
-
- always @(posedge clk)
- if (rst) begin
- /*AUTORESET*/
- // Beginning of autoreset for uninitialized flops
- CC <= 1'h0;
- regO <= 16'h0;
- regR <= 16'h0;
- // End of automatics
- end else if (ena) begin
- // 0x1: SET a, b - sets a to b
- // 0x2: ADD a, b - sets a to a+b, sets O to 0x0001 if there's an overflow, 0x0 otherwise
- // 0x3: SUB a, b - sets a to a-b, sets O to 0xffff if there's an underflow, 0x0 otherwise
- // 0x4: MUL a, b - sets a to a*b, sets O to ((a*b)>>16)&0xffff
- // 0x5: DIV a, b - sets a to a/b, sets O to ((a<<16)/b)&0xffff. if b==0, sets a and O to 0 instead.
- // 0x6: MOD a, b - sets a to a%b. if b==0, sets a to 0 instead.
- // 0x7: SHL a, b - sets a to a<<b, sets O to ((a<<b)>>16)&0xffff
- // 0x8: SHR a, b - sets a to a>>b, sets O to ((a<<16)>>b)&0xffff
- // 0x9: AND a, b - sets a to a&b
- // 0xa: BOR a, b - sets a to a|b
- // 0xb: XOR a, b - sets a to a^b
- if (pha == 2'o0)
- case (opc)
- 4'h2: regO <= {15'd0,c};
- 4'h3: regO <= {(16){c}};
- 4'h4: regO <= mul[31:16];
- 4'h7: regO <= shl[31:16];
- 4'h8: regO <= shr[15:0];
- default: regO <= regO;
- endcase // case (opc)
- if (pha == 2'o0)
- case (opc)
- 4'h0: regR <= src;
- 4'h1: regR <= tgt;
- 4'h2: regR <= add;
- 4'h3: regR <= add;
- 4'h4: regR <= mul[15:0];
- 4'h7: regR <= shl[15:0];
- 4'h8: regR <= shr[31:16];
- 4'h9: regR <= src & tgt;
- 4'hA: regR <= src | tgt;
- 4'hB: regR <= src ^ tgt;
- default: regR <= 16'hX;
- endcase // case (opc)
-
- /*
- if (pha == 2'o0)
- case (opc)
- 4'h0: {regO, regR} <= {regO, src};
- // 0x1: SET a, b - sets a to b
- 4'h1: {regO, regR} <= {regO, tgt};
- // 0x2: ADD a, b - sets a to a+b, sets O to 0x0001 if there's an overflow, 0x0 otherwise
- // 0x3: SUB a, b - sets a to a-b, sets O to 0xffff if there's an underflow, 0x0 otherwise
- // 0x4: MUL a, b - sets a to a*b, sets O to ((a*b)>>16)&0xffff
- // 0x5: DIV a, b - sets a to a/b, sets O to ((a<<16)/b)&0xffff. if b==0, sets a and O to 0 instead.
- // 0x6: MOD a, b - sets a to a%b. if b==0, sets a to 0 instead.
- 4'h2, 4'h3: {regO, regR} <= (opc[0]) ?
- {{(16){c}},as} :
- {15'd0,c,as};
- 4'h4: {regO, regR} <= {1'b0,src} * {1'b0,tgt}; // force 17x17 unsigned
- // 0x7: SHL a, b - sets a to a<<b, sets O to ((a<<b)>>16)&0xffff
- // 0x8: SHR a, b - sets a to a>>b, sets O to ((a<<16)>>b)&0xffff
- 4'h7: {regO, regR} <= src << tgt;
- 4'h8: {regR, regO} <= {src,16'h0} >> tgt;
-
- // 0x9: AND a, b - sets a to a&b
- // 0xa: BOR a, b - sets a to a|b
- // 0xb: XOR a, b - sets a to a^b
- 4'h9: {regO, regR} <= {regO, src & tgt};
- 4'hA: {regO, regR} <= {regO, src | tgt};
- 4'hB: {regO, regR} <= {regO, src ^ tgt};
- default: {regO, regR} <= {regO, 16'hX};
- endcase // case (opc)
- */
-
- // 0xc: IFE a, b - performs next instruction only if a==b
- // 0xd: IFN a, b - performs next instruction only if a!=b
- // 0xe: IFG a, b - performs next instruction only if a>b
- // 0xf: IFB a, b - performs next instruction only if (a&b)!=0
-
- if (pha == 2'o0)
- case (opc)
- 4'hC: CC <= (src == tgt);
- 4'hD: CC <= (src != tgt);
- 4'hE: CC <= (src > tgt);
- 4'hF: CC <= |(src & tgt);
- default: CC <= 1'b1;
- endcase // case (opc)
-
- end
-
- endmodule // dcpu16_alu
复制代码
- /*
-
- DCPU16 PIPELINE
- ===============
- Consists of the following stages:
- - Fetch (FE): fetches instructions from the FBUS.
- - Decode (DE): decodes instructions.
- - EA A (EA) : calculates EA for A
- - EA B (EB) : calculates EA for B
- - Load A (LA): loads operand A from ABUS.
- - Load B (LB): loads operand B from ABUS.
- - Execute (EX): performs the ALU operation.
- - Save A (SA): saves operand A to the FBUS.
- 0| 1| 2| 3| 0| 1| 2| 3| 0| 1| 2| 3
- FE|DE|EA|EB|LA|LB|EX|SA
- FE|DE|EA|EB|LA|LB|EX|SA
- FE|DE|EA|EB|LA|LB|EX|SA
- */
- // 775@155
- // 692@159
- // 685@160
- // 603@138
- // 573@138
- // 508@141
- // 502@149
- // 712@153
- // 679@162
- module dcpu16_cpu (/*AUTOARG*/
- // Outputs
- g_wre, g_stb, g_dto, g_adr, f_wre, f_stb, f_dto, f_adr,
- // Inputs
- rst, g_dti, g_ack, f_dti, f_ack, clk
- );
- /*AUTOOUTPUT*/
- // Beginning of automatic outputs (from unused autoinst outputs)
- output [15:0] f_adr; // From m0 of dcpu16_mbus.v
- output [15:0] f_dto; // From x0 of dcpu16_alu.v
- output f_stb; // From m0 of dcpu16_mbus.v
- output f_wre; // From m0 of dcpu16_mbus.v
- output [15:0] g_adr; // From m0 of dcpu16_mbus.v
- output [15:0] g_dto; // From x0 of dcpu16_alu.v
- output g_stb; // From m0 of dcpu16_mbus.v
- output g_wre; // From m0 of dcpu16_mbus.v
- // End of automatics
- /*AUTOINPUT*/
- // Beginning of automatic inputs (from unused autoinst inputs)
- input clk; // To c0 of dcpu16_ctl.v, ...
- input f_ack; // To c0 of dcpu16_ctl.v, ...
- input [15:0] f_dti; // To c0 of dcpu16_ctl.v, ...
- input g_ack; // To m0 of dcpu16_mbus.v
- input [15:0] g_dti; // To m0 of dcpu16_mbus.v
- input rst; // To c0 of dcpu16_ctl.v, ...
- // End of automatics
- /*AUTOWIRE*/
- // Beginning of automatic wires (for undeclared instantiated-module outputs)
- wire CC; // From x0 of dcpu16_alu.v
- wire bra; // From c0 of dcpu16_ctl.v
- wire ena; // From m0 of dcpu16_mbus.v
- wire [15:0] ireg; // From c0 of dcpu16_ctl.v
- wire [3:0] opc; // From c0 of dcpu16_ctl.v
- wire [1:0] pha; // From c0 of dcpu16_ctl.v
- wire [15:0] regA; // From m0 of dcpu16_mbus.v
- wire [15:0] regB; // From m0 of dcpu16_mbus.v
- wire [15:0] regO; // From x0 of dcpu16_alu.v
- wire [15:0] regR; // From x0 of dcpu16_alu.v
- wire [2:0] rra; // From c0 of dcpu16_ctl.v
- wire [15:0] rrd; // From r0 of dcpu16_regs.v
- wire [2:0] rwa; // From c0 of dcpu16_ctl.v
- wire [15:0] rwd; // From x0 of dcpu16_alu.v
- wire rwe; // From c0 of dcpu16_ctl.v
- wire wpc; // From m0 of dcpu16_mbus.v
- // End of automatics
- /*AUTOREG*/
- dcpu16_ctl
- c0 (/*AUTOINST*/
- // Outputs
- .ireg (ireg[15:0]),
- .pha (pha[1:0]),
- .opc (opc[3:0]),
- .rra (rra[2:0]),
- .rwa (rwa[2:0]),
- .rwe (rwe),
- .bra (bra),
- // Inputs
- .CC (CC),
- .wpc (wpc),
- .f_dti (f_dti[15:0]),
- .f_ack (f_ack),
- .clk (clk),
- .ena (ena),
- .rst (rst));
- dcpu16_mbus
- m0 (/*AUTOINST*/
- // Outputs
- .g_adr (g_adr[15:0]),
- .g_stb (g_stb),
- .g_wre (g_wre),
- .f_adr (f_adr[15:0]),
- .f_stb (f_stb),
- .f_wre (f_wre),
- .ena (ena),
- .wpc (wpc),
- .regA (regA[15:0]),
- .regB (regB[15:0]),
- // Inputs
- .g_dti (g_dti[15:0]),
- .g_ack (g_ack),
- .f_dti (f_dti[15:0]),
- .f_ack (f_ack),
- .bra (bra),
- .CC (CC),
- .regR (regR[15:0]),
- .rrd (rrd[15:0]),
- .ireg (ireg[15:0]),
- .regO (regO[15:0]),
- .pha (pha[1:0]),
- .clk (clk),
- .rst (rst));
-
- dcpu16_alu
- x0 (/*AUTOINST*/
- // Outputs
- .f_dto (f_dto[15:0]),
- .g_dto (g_dto[15:0]),
- .rwd (rwd[15:0]),
- .regR (regR[15:0]),
- .regO (regO[15:0]),
- .CC (CC),
- // Inputs
- .regA (regA[15:0]),
- .regB (regB[15:0]),
- .opc (opc[3:0]),
- .clk (clk),
- .rst (rst),
- .ena (ena),
- .pha (pha[1:0]));
-
-
- dcpu16_regs
- r0 (/*AUTOINST*/
- // Outputs
- .rrd (rrd[15:0]),
- // Inputs
- .rwd (rwd[15:0]),
- .rra (rra[2:0]),
- .rwa (rwa[2:0]),
- .rwe (rwe),
- .rst (rst),
- .ena (ena),
- .clk (clk));
-
- endmodule // dcpu16
复制代码 |