【发布时间】:2016-11-25 06:22:37
【问题描述】:
我正在使用 quartus 2 9.1。我在 verilog 上有一个单端口 RAM 程序,我添加了 reg
偶数
按第一位检查是奇数还是偶数,求和时为 1 或 0。我需要通过数据输入在ram中输入16个数字,然后计算有多少奇数和偶数。但我尝试了类似的东西:
output wire [4:0] count;
count = count + data[0]; //to count odd numbers, then i could take away from 16 and get even number - in simulation its just 0 or 1..
或类似的东西:
output wire [4:0] count;
always @*
begin
if(data[0])
even=1;
else
begin
even=0;
count = count + 1;
end
end
但计数不想显示奇数或偶数的 sumaliton 数。我的代码:
module kok
(
input [7:0] data,
input [5:0] addr,
input we, clk,
output [7:0] q,
output reg even
);
// Declare the RAM variable
reg [7:0] ram[63:0];
// Variable to hold the registered read address
reg [5:0] addr_reg;
always @ (posedge clk)
begin
// Write
if (we)
ram[addr] <= data;
addr_reg <= addr;
end
always @(posedge data)
begin
even = data[0];
end
// Continuous assignment implies read returns NEW data.
// This is the natural behavior of the TriMatrix memory
// blocks in Single Port mode.
assign q = ram[addr_reg];
endmodule
【问题讨论】:
标签: verilog