|
楼主 |
发表于 2015-1-7 17:42:07
|
显示全部楼层
[code][/code]module oc8051_rom_top(clk_osc,
clock,
rst,
addr,
inst_o);
input clk_osc,clock,rst;
input [15:0] addr;
output [31:0] inst_o;
reg [31:0] inst_o,inst;
reg [15:0] addr_r;
reg [2:0] cnt;
//实例化ROM IP
rom_64k oc8051_rom1( .clock(clk_osc),
.address(addr_r),
.q(q));
//计数
always@(posedge ~clk_osc or posedge rst)
begin
if(rst)
cnt <= 3'h0;
else if(clock&cnt<3'h6)
cnt <= cnt +3'h1;
else
cnt <= 3'h0;
end
//计算地址偏移量
always@(posedge ~clk_osc or posedge rst)
begin
if(rst)
addr_r<= 16'h0;
else if(cnt<3'h4)
addr_r <= addr+ cnt;
end
//将读取的4个字节依次存入buffer
always@(posedge clk_osc or posedge rst)
begin
if(rst)
inst <= 32'h0;
else if(clock)
case(cnt)
3'h0:inst[31:24] <= q;
3'h1:inst[23:16] <= q;
3'h2:inst[15:8] <= q;
3'h3:inst[7:0] <= q;
endcase
end
//将buffer中的指令合并、输出
always@(posedge clock or posedge rst)
begin
if(rst)
inst_o <= 32'h0;
else
inst_o <= inst;
end
endmodule |
|