完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
嗨,
我正在尝试为我的一个assignmnet编写一个简单的cpu电路的verilog代码。 我尝试过几个程序,但在尝试使用设计时遇到了编译错误。 我把它简化为一个基本的cpu,它有一个带有ALU的控制器和一个内存块。 在此阶段,ALU只能添加/减去无符号数。 我想使用xilinx库中的RAM16x4作为内存并在我的程序中实现它。 如果有人可以帮我弄清楚代码中的错误,我写的代码如下。 我很可能能够在原理图模块中单独使用控制器和RAM并通过相关端口连接它们,但我很想知道代码中的错误。 非常狡猾。 module cpu(reset_cpu,clock,run); 输入时钟,reset_cpu,run; //输出[3:0] mar,mbr_inout; //输出mem_write; reg [3:0] pc,ir,mar,mbr,dreg; reg fetch_complete,mem_write; wire clock,reset_cpu, 跑; RAM16X4S mem1(.O0(mbr_inout(0)),. O1(mbr_inout(1)),. O2(mbr_inout(2)),. O3(mbr_inout(3)),. A0(mar(0)),. A1 (mar(1)),。A2(mar(2)),。A3(mar(3)),. D0(mbr_inout(0)),。D1(mbr_inout(1)),。D2(mbr_inout(2) ),。DW3(mbr_inout(3)),. WCLK(时钟),. WE(mem_write)); 总是@(posedge clock)beginif(reset_cpu)pc = 0; fetch_complete = 0; else case(fetch_complete)1'b1:beginir [1:0] = mbr [3:2]; mar [1:0] = mbr [ 1:0]; case(ir)4'bxx00:开始mem_write = 0; mbr = mbr_inout; dreg = mbr; 结束// load4'bxx01:开始mem_write = 0; mbr = mbr_inout; dreg = dreg + mbr; 结束// add4'bxx10:开始mem_write = 0; mbr = mbr_inout; dreg = dreg - mbr; 结束// subtract4'bxx11:开始mbr = dreg; mbr_inout = mbr; mem_write = 1; ; 结束// storeendcaseend1'b0:开始// wt = 0; mem_write = 0; mar = pc; mbr = mbr_inout; pc = pc + 1; fetch_complete = 1; endendcase endendmodule 以上来自于谷歌翻译 以下为原文 Hi, I am trying to write a verilog code for a simple cpu circuit for one of my assignmnets. I have tried few programs but got compiling errors when trying to inplement the design. I have simplified it to a basic cpu which has controller with a ALU in it and a memory block. At this stage ALU can only add/subtract unsigned numbers. I want to use the RAM16x4s from xilinx library as the memory and instatiate it in my program. The code I have written is below if someone can help me to figure out the mistake in the code. I most probably will be able to use the controller and RAM seperately in a schematic module and connect them through the relevant ports, but I am keen to figure out the error in the code. Thnaks very much. module cpu(reset_cpu, clock, run); input clock, reset_cpu, run; //output [3:0] mar, mbr_inout; //output mem_write; reg [3:0] pc, ir, mar, mbr, dreg; reg fetch_complete, mem_write; wire clock, reset_cpu, run; RAM16X4S mem1 (.O0 (mbr_inout(0)), .O1 (mbr_inout(1)), .O2 (mbr_inout(2)),.O3 (mbr_inout(3)), .A0 (mar(0)),.A1 (mar(1)), .A2 (mar(2)), .A3 (mar(3)), .D0 (mbr_inout(0)), .D1 (mbr_inout(1)), .D2 (mbr_inout(2)), .D3 (mbr_inout(3)), .WCLK (clock), .WE (mem_write)); always @(posedge clock) begin if (reset_cpu) pc=0; fetch_complete =0; else case (fetch_complete) 1'b1 : begin ir[1:0] = mbr[3:2]; mar[1:0] = mbr[1:0]; case (ir) 4'bxx00 : begin mem_write =0; mbr = mbr_inout; dreg = mbr; end // load 4'bxx01 : begin mem_write =0; mbr = mbr_inout; dreg = dreg + mbr; end // add 4'bxx10 : begin mem_write =0; mbr = mbr_inout; dreg = dreg - mbr ; end // subtract 4'bxx11 : begin mbr= dreg; mbr_inout = mbr; mem_write =1; ; end// store endcase end 1'b0 : begin //wt =0; mem_write=0; mar = pc; mbr= mbr_inout; pc=pc+1; fetch_complete =1; end endcase end endmodule |
|
相关推荐
1个回答
|
|
首先,如果你不希望mbr_inout成为模块端口,你需要为它定义一个连线或者其他
你有位选择的问题。 接下来,您需要使用方括号进行位选择,例如 mbr_inout [0],而不是mbr_inout(0)。 接下来,当有更多时,你需要一个开始..结束括号if和else语句 不止一个。 (参见“if(reset_cpu)”)。 然后你连续有两个分号,Verilog不喜欢这样。 最后你将总线mbr_inout分配给RAM的输出端口,但也是 在作业中作为登记册驱动: 4'bxx11:开始mbr = dreg; mbr_inout = mbr; mem_write = 1; 结束//商店 此总线只能有一个源,RAM或寄存器。 如果你有时需要一个,有时需要另一个,你需要 创建另一个总线并使用多路复用器来选择合适的总线 信号。 祝你好运, 的Gabor - Gabor 以上来自于谷歌翻译 以下为原文 First, if you don't want mbr_inout to be a module port, you'll need to define a wire for it or else you have problems with bit selects. Next you need to use square brackets for bit selects e.g. mbr_inout[0], not mbr_inout(0). Next you need a begin .. end bracketing the if and else statements when there are more than one. (see "if (reset_cpu)" ). Then you have two semicolons in a row, Verilog doesn't like that. Finally you have bus mbr_inout assigned to the output ports of the RAM, but also driven as a register in the assignment: 4'bxx11 : begin mbr= dreg; mbr_inout = mbr; mem_write =1; end// store You can have only one source for this bus, either the RAM or a register. If you need one sometimes and the other at other times, you'll need to create another bus and use a multiplexer to select the appropriate signals. Good luck, Gabor -- Gabor |
|
|
|
只有小组成员才能发言,加入小组>>
2380 浏览 7 评论
2797 浏览 4 评论
Spartan 3-AN时钟和VHDL让ISE合成时出现错误该怎么办?
2262 浏览 9 评论
3335 浏览 0 评论
如何在RTL或xilinx spartan fpga的约束文件中插入1.56ns延迟缓冲区?
2428 浏览 15 评论
有输入,但是LVDS_25的FPGA内部接收不到数据,为什么?
756浏览 1评论
请问vc707的电源线是如何连接的,我这边可能出现了缺失元件的情况导致无法供电
544浏览 1评论
求一块XILINX开发板KC705,VC707,KC105和KCU1500
365浏览 1评论
1962浏览 0评论
681浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-22 16:37 , Processed in 1.181736 second(s), Total 47, Slave 40 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号