本文介绍了VHDL 转换为 verilog的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将以下 VHDL 代码转换为 Verilog.但是我遇到了我在这里提到的一些问题编译错误一>.有人能给我一些关于如何在 Verilog 中正确编写相同函数的提示吗?
I would like to convert the following VHDL code into Verilog. But I ran into some problems as I mentioned herecompilation error.Could some one give me some hints of how to properly write the same function in Verilog?
谢谢!
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
use work.classic_multiplier_parameters.all;
entity poly_multiplier is
port (
a, b: in std_logic_vector(M-1 downto 0);
d: out std_logic_vector(2*M-2 downto 0)
);
end poly_multiplier;
architecture simple of poly_multiplier is
type matrix_ands is array (0 to 2*M-2) of STD_LOGIC_VECTOR(2*M-2 downto 0);
signal a_by_b: matrix_ands;
signal c: std_logic_vector(2*M-2 downto 0);
begin
gen_ands: for k in 0 to M-1 generate
l1: for i in 0 to k generate
a_by_b(k)(i) <= A(i) and B(k-i);
end generate;
end generate;
gen_ands2: for k in M to 2*M-2 generate
l2: for i in k to 2*M-2 generate
a_by_b(k)(i) <= A(k-i+(M-1)) and B(i-(M-1));
end generate;
end generate;
d(0) <= a_by_b(0)(0);
gen_xors: for k in 1 to 2*M-2 generate
l3: process(a_by_b(k),c(k))
variable aux: std_logic;
begin
if (k < M) then
aux := a_by_b(k)(0);
for i in 1 to k loop aux := a_by_b(k)(i) xor aux; end loop;
else
aux := a_by_b(k)(k);
for i in k+1 to 2*M-2 loop aux := a_by_b(k)(i) xor aux; end loop;
end if;
d(k) <= aux;
end process;
end generate;
end simple;
推荐答案
下面的代码部分应该可以做到.备注:
The code section below should do it.Notes :
- 在您的代码中,常量
M
被定义为一个单独的包,我已将其移动为参数 (Verilog) 或通用 (VHDL) - Verilog 区分大小写,因此您必须修正
M
、a
和b
的拼写
- in your code, constant
M
is defined is a separate package, I've moved it to be a parameter (Verilog) or generic (VHDL) - Verilog is case-sensitive, so you have to fix the spelling of
M
,a
andb
Verilog 代码:
Verilog code:
module poly_multiplier(a, b, d);
parameter M = 0;
input [M - 1:0] a;
input [M - 1:0] b;
output [2 * M - 2:0] d;
wire [M - 1:0] a;
wire [M - 1:0] b;
reg [2 * M - 2:0] d;
wire [2 * M - 2:0] a_by_b[0:2 * M - 2];
wire [2 * M - 2:0] c;
generate
genvar k0;
for (k0 = 0; k0 <= M - 1; k0=k0+1) begin : gen_ands
genvar i0;
for (i0 = 0; i0 <= k0; i0=i0+1) begin : l1
assign a_by_b[k0][i0] = a[i0] & b[k0 - i0];
end
end
endgenerate
generate
genvar k1;
for (k1 = M; k1 <= 2 * M - 2; k1=k1+1) begin : gen_ands2
genvar i1;
for (i1 = k1; i1 <= 2 * M - 2; i1=i1+1) begin : l2
assign a_by_b[k1][i1] = a[k1 - i1 + M - 1] & b[i1 - M + 1];
end
end
endgenerate
always @(*) begin
d[0] = a_by_b[0][0];
end
generate
genvar k2;
for (k2 = 1; k2 <= 2 * M - 2; k2=k2+1) begin : gen_xors
reg aux;
integer i;
always @(*) begin : P2
if ((k2 < M)) begin
aux = a_by_b[k2][0];
for(i = 1; i <= k2; i = i + 1) begin
aux = a_by_b[k2][i] ^ aux;
end
end
else begin
aux = a_by_b[k2][k2];
for(i = k2 + 1; i <= 2 * M - 2; i = i + 1) begin
aux = a_by_b[k2][i] ^ aux;
end
end
d[k2] = aux;
end
end
endgenerate
endmodule
这篇关于VHDL 转换为 verilog的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!