Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Question about Verilog code

Status
Not open for further replies.

aobosong

Newbie level 5
Joined
Feb 27, 2011
Messages
9
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,352
Hello

It is probably common knowledge but I don't know what to Google:

I have this snippet of Verilog code here I want to convert to VHDL:

Code:
reg [8:0] error;
reg [11:0]  b1;
b1 = {{3{error[8]}},error};

Thanks!
 

You'll want to review concatenation and replication statement syntax.

As far as I'm aware of, there's no similar repeat (replication) operator in VHDL, so you'll write

Code:
b1 <= error(8) & error(8) & error(8) & error;
 

By the way, what the code is doing is called sign extension and can be easily written in SystemVerilog with

b1 = signed'(error);

In VHDL this would look like

Code:
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_SIGNED.ALL;
[...]
b1 <= SXT(error, b1'LENGTH);
 

In VHDL this would look like
Yes, a sign extension function is in fact the more elegant way in this case. I admit that I wasn't looking for the meaning of the concatenation operation.
 

I'm not sure if these work together, but VHDL also has a form of replication.

(0 to 2 => error(8)) & error

Though I think I put this on two lines, assigning one signal slice to (others => error(8)), and the other slice to error.

In this case, sign extend seems better suited though.
 

By the way, what the code is doing is called sign extension and can be easily written in SystemVerilog with

b1 = signed'(error);

In VHDL this would look like

Code:
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_SIGNED.ALL;
[...]
b1 <= SXT(error, b1'LENGTH);

With standard VHDL you need the resize() function.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top