On 15 Apr 2007 08:29:46 -0700, "Mahurshi Akilla"
<
[email protected]> wrote:
>Another question: Is there a difference between saying "assign
>alu_result = op1 - op2" and saying "alu_result = op1 - op2" ?
YES!!!!!
If you write "assign something = expression;" inside a
procedural block (always block) in a design, you are
almost certainly doing the wrong thing. Who allowed
you to get away with this in your original coursework?
If it's from a textbook, tell me the name of the book
so I can tell my students that they should burn it :-)
The assign keyword does two wildly different things in
Verilog. You can use it *inside* an always or initial
block, as in your ALU. This is bad - I'll explain why
later. The common, sensible, OK-for-design use is
to put it at the top level of a module, outside any
always blocks:
module adder ( input [7:0] a,b, output [8:0] sum );
assign sum = a + b;
endmodule
In this case your "assign"...
* is driving a net (wire) - "sum" in this example;
* represents a driver (gate output) permanently
connected to the driven net;
* automatically updates whenever the expresson (a+b)
changes;
* is a completely sensible representation of a piece
of combinational logic.
There is, of course, an alternative. You could
write the same thing in an always block:
module adder ( input [7:0] a,b, output reg [8:0] sum );
always @(a or b) begin
sum = a + b;
end
endmodule
Note, now, that "sum" must be a variable - hence the "reg"
declaration in the port list. Once again, this is a
good and useful synthesisable description of an adder.
But your code contained stuff like this...
always @...
assign sum = a + b;
OUCH! This is a COMPLETELY different form of "assign".
It's a "procedural continuous assignment". It says that
when you execute that line of code, Verilog sets up a
process that monitors a and b, and whenever they change
it will calculate a+b and write that value to "sum".
This procedural continuous assignment will remain active
until you execute a different "assign sum = ...".
Your code, then, was effectively asking Verilog to switch-in
a completely new piece of hardware each time the opcode
changed! Most synthesis tools will not process that code.
Procedural continuous assigns can be useful for modelling
certain kinds of asynchronous load operation, but in my
opinion you should NEVER use them in synthesisable design.
--
Jonathan Bromley, Consultant
DOULOS - Developing Design Know-how
VHDL * Verilog * SystemC * e * Perl * Tcl/Tk * Project Services
Doulos Ltd., 22 Market Place, Ringwood, BH24 1AW, UK
[email protected]
http://www.MYCOMPANY.com
The contents of this message may contain personal views which
are not the views of Doulos Ltd., unless specifically stated.