DSD Module 2
DSD Module 2
MP Sim
VERILOG vs
VHDL
VERILOG HDL VHDL
port declarations
— Interface: consisting of port and parameter
parameter declarations declarations
`include directives
— optional add-ons
variable
— body: specification of internal declarations
part of the module assignments
low-level module instantiation
initial and always blocks
task and function
endmodule
MODULE - EXAMPLE
It begin with back slash (\) and end with white space
Unsized numbers
Default base is decimal
Default size is at least 32 (depends on Verilog compiler)
Examples
23232
’habc
’o234
Negative numbers
Put the sign before the <size>
Examples:
-6’d35
4’d-12 // illegal
LEXICAL CONVENTIONS
NUMBERS
X or Z values
– Unknown value: lowercase x or Uppercase X
• 4 bits in hex, 3 bits in octal, 1 bit in binary
– High-impedance value: lowercase z or Uppercase Z
• 4 bits in hex, 3 bits in octal, 1 bit in binary
– Examples
• 12’h13x
• 4’hX
• 32’bz
Strings
As in C, use double-quotes
Examples:
“Hello world!”
“a / b”
“text\tcolumn1\bcolumn2\n”
DATA TYPES
NET
Two groups of data types:
Net: it represents connection between hardware elements
Registers: represents an abstract data storage element
Nets are one-bit value unless they are declared as vectors and
default value of net isZ
Examples: wire a; wire b, c; wire d=1’b0;
DATA TYPES
NET TYPES
A net declaration starts with keyword wire addr
… …
or
Process
y
Memor
wire r_w; // scalar signal data
wire [7:0] data; // vector signal
wire [9:0] addr; // vector signal r_w
… …
Different kinds of net data types are:
or
Process
y
Memor
wire r_w; data[7:0]
wire [7:0] data; status[3:0]
wire [9:0] addr; i_o[7:0] r_w
… …
endmodule
DATA TYPES
REGISTERS
A register type represents data storage elements or avariable that can
hold a value
It can assign avalue only within always or initial statement and default
value of register is X
Examples:
integer count;
integer addr [3:0];
initial
begin
count=count+1;
DATA TYPES
REGISTERS TYPES
(b) REAL
Real registers are used to specify the variable in decimal or scientific
notation and they are declared with the keyword real
35
DATA TYPES
REGISTERS TYPES
(c) TIME
Time register is used to store and manupulate time values
They areusedto store simulation time andit isdeclared with the keyword
time
Examples:
time currtime;
initial
begin
currtime=$time;
end
DATA TYPES
REGISTERS TYPES
(d) VECTORS
Net or reg data can be declared as vector, if bit width is not specified, the default
is scalar (1-bit)
Examples: wire b; //scalar net variable
wire[7:0] databus; //8-bit data bus
Represent buses
wire[3:0] busA;
reg [1:4] busB;
reg [1:0] busC;
Left number isMS bit
Vector assignment (by position!!)
busB[1] = busA[3];
busB[2] = busA[2];
busB[3] = busA[1];
busB[4] = busA[0];
DATA TYPES
REGISTERS TYPES
(e)ARRAY
Array are used to declare multi-dimensional variable
Array types are used for reg, integer, data types and array are accessed by:
<array_name>[<subscript>]
Each element of array is known aselement or word and it is addressed by single array
index
Parameter can be assigned a value only once using declaration and its form is
Example:
… …
parameter bussize = 8;
Parameter bit=1, byte=8;
reg [bussize-1 : 0] databus;
… …
DATA TYPES
RESTRICTION ON DATA TYPES
• Behavioral Modeling
– Can use only reg data type
(within initial and always constructs)
– Cannot use wire data type
OPERATORS
ARITHMETIC OPERATORS
+, -, *, /, %,**
If any operand is x the result is x
Negative registers:
-regs can be assigned negative but are treated asunsigned
reg [15:0] regA;
..
regA = -4’d12; // stored as 216-12 =
65524 regA/3 evaluates to 21861
OPERATORS
LOGICAL OPERATORS
&& logical AND
|| logical OR
! logical NOT
| OR
^ XOR
~& NAND
~| NOR
~^ or ^~ XNOR
Replication ..
catr = {4{a}, b, 2{c}}; // catr = 1111_010_101101
OPERATORS
CONDITIONAL OPERATORS
cond_expr ? true_expr : false_expr
A
1
Y
B Y = (sel)? A : B;
0
sel
Use parentheses to
enforce your priority
VERILOG MODELING
STRUCTURAL
BEHAVIORAL
SWITCH
63
STRUCTURAL MODELING
At gate level, the circuit is described in terms of gates (e.g., and,
nand)
Hardware design at this level is in built for a user with a basic
knowledge of digital logic design
Because it is possible to see a one-to-one correspondence
between the logic circuit diagram and the Verilog description
Actually, the lowest level of abstraction is switch- (transistor-)
level modeling
However, with designs getting very complex, very few hardware
designers work at switch level. So most of the digital design is
now done at gate level or higher levels of abstraction.
54
STRUCTURAL MODELING
GATE PRIMITIVES
All logic circuits can be designed by using basic gates. Verilog
supports basic logic gates as predefined primitives. There are
three classes of basic gates.
OR GATE
// Module Name: Orgate
module Orgate(i1, i2, out);
input i1;
input i2;
output out;
or(out,i1,i2);
endmodule
56
STRUCTURAL MODELING
NAND GATE
// Module Name:
Nandgat
e module Nandgate(i1, i2,
out);
input i1;
input i2;
output out;
nand(out,i1,i2);
endmodule
NOR GATE
// Module Name: Norgate
module Norgate(i1, i2, out);
input i1;
input i2;
output out;
nor(out,i1,i2); 57
STRUCTURAL
MODELING
XORGATE
// Module Name: Xorgate
module Xorgate(i1, i2, out);
input i1;
input i2;
output out;
xor(out,i1,i2);
endmodule
XNORGATE
// Module Name: Xnorgate
module Xnorgate(i1, i2, out);
input i1;
input i2;
output out;
xnor(out,i1,i2);
endmodule
ECE2003 – DIGITAL LOGIC DESIGN 58
STRUCTURAL MODELING
Basic syntax for multiple-output gates is:
Multiple_output_Gate_type [instance_name] (output1, output2,……..outputn, input);
BUFFER GATE
// Module Name: Buffer
module Buffer(in, out);
input in;
output out;
buf(out,in);
endmodule
NOT GATE
// Module Name: Notgate
module Notgate(in, out);
input in;
output out;
not(out,in);
endmodule
ECE2003 – DIGITAL LOGIC DESIGN 59
STRUCTURAL MODELING
Basic syntax for tristate-gates is:
Tristate_type [instance_name] (output,input,control);
BUFIF1 GATE
// Module Name: Bufif1
out module Bufif1(in, out, con);
in
input in,con;
Out=in if con=1 output out;
con Else out=Z
bufif1(out,in,con);
endmodule
BUFIF0 GATE
// Module Name: Bufif0
module Bufif0(in, out, con);
in out input in,con;
Out=in if con=0 output out;
con Else out=Z bufif0(out,in,con);
endmodule
ECE2003 – DIGITAL LOGIC DESIGN 60
STRUCTURAL MODELING
NOTIF1 GATE
NOTIF0 GATE
61
STRUCTURAL MODELING
EXAMPLE – 2:1MUX
62
STRUCTURAL MODELING
MODULE
63
STRUCTURAL MODELING
MODULENAME
64
STRUCTURAL MODELING
PORT LIST
65
STRUCTURAL MODELING
INPUT/OUTPUT DECLARATION
66
STRUCTURAL MODELING
DATA TYPE DECLARATION
67
STRUCTURAL MODELING
GATE INSTATIATION
68
STRUCTURAL MODELING
GATE INSTATIATION
69
STRUCTURAL MODELING
HALFADDER
70
FULLADDER
STRUCTURAL MODELING
FULLADDERUSING MODULE INSTATIATION
71
4-BIT PARALLEL ADDER
STRUCTURAL MODELING
4-BIT PARALLELADDERUSING MODULEINSTATIATION
module adder_4bit (S, COUT,A,B);
output [3:0]S ;
output COUT ;
input [3:0] A ;
input [3:0] B ;
wire [2:0]C;
FullAdder FA0(S[0],C[0],A[0],B[0],1'b0);
FullAdder FA1(S[1],C[1],A[1],B[1],C[0]);
FullAdder FA2(S[2],C[2],A[2],B[2],C[1]);
FullAdder FA3(S[3],COUT,A[3],B[3],C[2]);
endmodule
71
STRUCTURAL MODELING
// Module Name: Mux4to1
4:1MUX module Mux4to1(i0, i1, i2, i3, s0, s1,out);
input i0;
input i1;
input i2;
input i3;
input s0;
input s1;
output out;
wire s1n,s0n;
wire y0,y1,y2,y3;
not (s1n,s1);
not (s0n,s0);
and (y0,i0,s1n,s0n);
and (y1,i1,s1n,s0);
and (y2,i2,s1,s0n);
and (y3,i3,s1,s0);
or (out,y0,y1,y2,y3);
endmodule
72
STRUCTURAL MODELING
// Module Name: Dux1to4
1:4 DEMUX
module Dux1to4(in, s0, s1, out0, out1, out2, out3);
input in;
input s0;
input s1;
output out0;
output out1;
output out2;
output out3;
wire s0n,s1n;
not(s0n,s0);
not(s1n,s1);
and (out0,in,s1n,s0n);
and (out1,in,s1n,s0);
and (out2,in,s1,s0n);
and (out3,in,s1,s0);
endmodule
73
STRUCTURAL MODELING
2:4DECODER
FULLADDER
74
STRUCTURAL MODELING
EXERCISE
Binary Subtractor
Parallel Adder
Binary Multiplier
Magnitude Comparator-4 bit
Decoders
Encoders
Mux
Demux
Parity generator and checker.
75
BEHAVIORAL MODELING
77
BEHAVIORAL MODELING
Behavioral model enables you to describe the system at ahigher
level of abstraction
78
BEHAVIORAL MODELING
PROCEDURAL BLOCK
In Verilog procedural block are the basic of behavior modeling
We can describe a one logic in one procedural block
Procedural block types: (i) initial (ii) always
All initial & always statement execute concurrently starting at time t=0
A module may contain any number of initial & always statement
Structure of procedural block
Type of block: initial or always
type-of-block @ (sensitivity list)
Symbol used to signifies event
begin : name-of-block; (only for always block)
local variable declaration;
procedural assignment statements;Specify the event which starts the execution of
block (only for always block)
the
end
A block can assign a name for the block
Variables which are local to the block are
defined here
This form the body of the block
All action within blocks are enclosed by begin-
end construct
79
76
BEHAVIORAL MODELING
PROCEDURAL BLOCK - INITIAL STATEMENT
Initial statement causesprocedural statement to executes only once and it begin
its execution at start of simulation time 0.
The if, case,for loop, and while loop must appear inside an always
block
module clock_gen;
reg clock, temp;
83
BEHAVIORAL MODELING
BLOCKING PROCEDURAL ASSIGNMENT
A procedural statement in which the assignment operator is an “ = “ in a blocking
procedural assignment Example: reg B=55;
Blocking procedural assignment is executed before any of the statement that follow it are
executed
Example: // Full adder using blocking procedural statement
module FA(sum,cout,A,B,C)
input A,B,C;
output sum, cout;
always @ ( A or B or C)
begin
reg C1,C2,C3;
sum=A&C;
C1=A&B;
C2=B&C;
C3=A&C;
Cout= C1|C2|C3;
end
endmodule
The sumassignment occurs first, sum is computed, then second statement is executes C1
is assigned and then third executed and C2 is assigned and so on
84
BEHAVIORAL MODELING
NON-BLOCKING PROCEDURAL ASSIGNMENT
The main characteristics of non-blocking assignment statement is
execution is performed concurrently
Example: c<=a&b;
In non-blocking assignment the assignment symbol “<=“ is used
Example:
always @ ( posedge clk)
begin
a<=b;
@ (negedge clk)
c<=b&(~c);
#2 b<=c;
endmodule
‘a’ is assigned the stored value of ‘b’ this activity is carried out concurrently
At the negative edge clock ‘c’ is assigned avalue of b&(~c)
Two nanoseconds later positive edge clock assign ‘c’ value to ‘b’
85
BEHAVIORAL MODELING
BLOCKING vsNONBLOCKING
Blocking Non-blocking
<variable> = <statement> <variable> <= <statement>
The keywords begin and end are used to group statements into sequential blocks.
Sequential blocks have the following characteristics:
The statements in asequential block are processed in the order they are specified
A statement is executed only after its preceding statement completes execution
If delay or event control is specified, it is relative to the simulation time when the previous statement in the
block completed execution
//Illustration 1: Sequential block without delay //Illustration 2: Sequential blockswith delay
reg X, Y; reg x, y;
reg [1:0] z, w; reg [1:0] z, w;
initial initial
Begin begin
x = l'bO; x = l'bo; //completes at simulation time 0
y = l‘b1; #5 y = l'bl; //completes at simulation time 5
z = {x, y};
#10 z = {x, y}; //completes at simulation time 15
w = {y, x} ; #20 w = {y, x); //completes at simulation time 35
End end
87
BEHAVIORAL MODELING
BLOCKING STATEMENT - PARALLEL BLOCK
Parallel blocks, specified by keywords fork and join, provide interesting
simulation features
All statements in aparallel block start at the time when the block wasentered.
Thus, the order in which the statements are written in the block is not
important. //Example : Parallel blockswith delay
reg x, y;
reg [ 1 : 0 ] z, w;
The result of simulation remains the initial
fork
same except that all statements start in x = l'bO; //completes at simulation time 0
parallel at time 0. Hence, the block #5 y = l'b1; //completes at simulation time 5
#10z{x, y}; //completes at simulation time 10
finishes at time 20 instead of time 35. #20w = {y, x}; //completes at simulation time
join
88
BEHAVIORAL MODELING
CONDITIONAL STATEMENT - IF
Conditional statements are used for making decisions based upon certain
conditions
These conditions are used to decide whether or not astatement should execute
89
BEHAVIORAL MODELING
CONDITIONAL STATEMENT - CASE
The keywords case, endcase, and default are used in the casestatement
The expression is compared to the alternatives in the order they are written
module mux4_to_1(out, iO, i1, i2, i3, sl, sO); input
For the first alternative that matches,the corresponding
iO, i1, i2, i3; statement or block is
input s1. sO; //Port declarationsfrom the I/O diagram
executed. If none of the alternatives match, the default_statement is executed.
output out; reg out;
The default_statement is optional. always @(sl or sO or iO or i1 or i2 or i3)
case ({sl, sO}) //Switch based on concatenation signals
2'dO :out iO;
syntax: 2'd1 : out i1;
2'd2 : out i2;
case(case_expression) 2'd3 : out i3;
case_item_expression {case_item_expression} default: $display("Invalid control signals"); endcase
procedural statement endmodule
… … …
… … …
default:procedural_statement
endcase
91
BEHAVIORAL MODELING
CONDITIONAL STATEMENT - FORLOOP
92
BEHAVIORAL MODELING
CONDITIONAL STATEMENT - WHILE LOOP
All looping statements can appear only inside an initial or always block. Loops
may contain delay expressions
The while loop executes until the while-expression becomes false. If the loop is
entered when the while-expression is false, the loop is not executed at all
A repeat construct cannot be used to loop on a general logical expression. A while loop is
used for that purpose.
A repeat construct must contain anumber, which can be aconstant, or a variable value.
However, if the number is avariable or signal value, it is evaluated only when the loop
starts and not during the loop execution. //EXAMPLE : increment and display count from ato 127
integer count;
initial
begin
syntax:
count = 0;
repeat(128)
repeat [loop count] begin
procedural_statement $display("Count = %d", count);
count = count + 1;
end
end
94
BEHAVIORAL MODELING
CONDITIONAL STATEMENT - FOREVER LOOP
The keyword forever is used to express this loop. A forever loop can be exited by
use of the disable statement.
The loop does not contain any expression and executes forever until the $finish
task is encountered.
The loop is equivalent to awhile loop with an expression that always true, e.g.,
while (1).
96
BEHAVIORAL MODELING
4x1 MUX
97
BEHAVIORAL MODELING
2 to 4 DECODER
98
BEHAVIORAL MODELING
2 to 4 DECODER
99
BEHAVIORAL MODELING
4 to 2 ENCODER
100
BEHAVIORAL MODELING
4 to 2 PRIORITY ENCODER
101
BEHAVIORAL MODELING
4 to 2 PRIORITY ENCODER
102
103
DATAFLOW MODELING
Dataflow level description of adigital circuit isat higher level, it makesthe
circuit description more compact ascompared to designthrough gate
primitives
The assignment statement start with the keyword assign and results are
assigned to nets
Continuous assignment – most basic statement used to drive value onto net
104
DATAFLOW MODELING
Implicit continuous assignment – it is the shortcut method of assigning the
expression on the net
Example: //regular continuous assignment
wire c,a,b;
assign c=a&b;
//implicit continuous assignment
wire c=a&b;
Implicit net declaration – if asignal nameof the left handsideof the continuous
assignmentstatement isnot declared the verilog simulator assignanimplicit net
declaration for the net
105
DATAFLOW MODELING
Regular assignment delay – the assignment takes effect with the time delay of 2 time
steps. If the values of ‘a’ and ‘b’ changes then ‘c’ wait for two time steps to compute
the result.
Net declaration delay – adelay can be specified on anet when it is declared without
putting acontinuous assignment on the net
Example: wire #5 c;
assign c=a&b;
106
DATAFLOW MODELING
EXPRESSIONS
An expression is formed using operands & operators
Expression can be used whenever a value is expected
Example: a & b, x1[7:0] + x2[7:0]
OPERANDS
Operands are the data types used in the expression
An operands can be constant, net, parameter, register, memory, bit select
Example: c = a + b // a, b, c are real operands
OPERATORS
Operators act on operands to produce desired result
Various types: arithmetic, logical, relational, equality, bitwise, shift, etc.,
Example: c = a % b // %is operator to perform modules operation on a,b
107
DATAFLOW MODELING
FULL ADDER • HALF ADDER
module fa_da(a,b,cin,sum,cout);
input a,b,cin; • module halfadder(s,c,a,b);
output sum,cout; input a,b;
assign sum=a^b^cin;
assign cout=(a&cin)|(b&cin)|(a&b); •output s,c; assign s=a^b;
endmodule assign c=a&b;
endmodule
108
4-Bit Full Adder Verilog Code and Testbench in ModelSim
module fulladd4(A,B,Cin,SUM,Cout);
output[3:0]SUM;
output Cout;
input [3:0]A,B;
input Cin;
assign {Cout, SUM}= A+B+Cin;
endmodule
Test Bench (TB)
module TB_FA();
reg[3:0]a,b;
reg c_in;
wire[3:0]s;
wire c_o;
fulladd4 f1(.A(a),.B(b),.Cin(c_in),.SUM(s),.Cout(c_o));
initial
begin
a= 4'b0000;b= 4'b0001;c_in= 1'b0;
#100;
end
endmodule
DATAFLOW MODELING
8:1 MUX
module mux(y,s,i);
input [2:0]s;
input[7:0]i;
output y;
assign y= (~s[2] & ~s[1] & ~s[0] & i[1]) |(~s[2] &
~s[1] & s[0] & i[2]) | (~s[2] & s[1] & ~s[0] &
i[3]) |(~s[2] & s[1] & s[0] & i[4]) |(s[2] & ~s[1] &
~s[0] & i[5]) | (~s[2] & s[1] & ~s[0] & i[6]) | (s[2] &
s[1] & ~s[0] & i[7]) |(s[2] & s[1] & s[0] & i[8]);
endmodule
109
DATAFLOW MODELING
BINARY TO GRAY CODE CONVERTER
module binary_to_gray(g,b);
input [3:0]b;
output[3:0]g;
assign g[3]= b[3];
assign g[2]= b[2]^b[3];
assign g[1]= b[1]^b[2];
assign g[0]= b[0]^b[1];
endmodule
110
DATAFLOW MODELING
111
DATAFLOW MODELING
8:3 PRIORITY ENCODER
module PriorityEncoder_DataFlow(code,data);
input[7:0]data;
output[2:0]code;
wire [7:0]w;
assign w[0]=(~data[0]);
assign w[1]=(~data[1]);
assign w[2]=(~data[2]);
assign w[3]=(~data[3]);
assign w[4]=(~data[4]);
assign w[5]=(~data[5]);
assign w[6]=(~data[6]);
assign w[7]=(~data[7]);
assigncode[0]=(w[7]&w[6]&w[5]&w[4]&w[3]&w[2]&data[1])|
(w[7]&w[6]&w[5]&w[4]&data[3])|(w[7]&w[6]&data[5])|data[7];
assign code[1]=(w[7]&w[6]&w[5]&w[4]&w[3]&data[2])|
(w[7]&w[6]&w[5]&w[4]&data[3])|(w[7]&data[6])|data[7];
assign code[2]=(w[7]&w[6]&w[5]&data[4])|(w[7]&w[6]&data[5])|(w[7]&data[6])|data[7];
endmodule
112
113
TEST BENCH
INTRODUCTION
We need to apply appropriate stimulus to the design in order to
test it. This can be done by writing another Verilog code called the
‘Test Bench’. This is written as a separate file, different from the
design file(s).
Examples:
$display("%d %b %b",A,B,C);
$monitor($time„"%b %b %h" , s1,s2,outvalue);
115
TEST BENCH
INTRODUCTION
116
TEST BENCH
INTRODUCTION
117
TEST BENCH
118
TEST BENCH – AND GATE
119
TEST BENCH – HALF ADDER
120
TEST BENCH – FULL ADDER
121
TEST BENCH – FULL ADDER
122
TEST BENCH – 4:1 MUX
123
TEST BENCH – 4:1 MUX
124
Design a 4x1 Mux, 2:4 Decoder & 4:2 Encoder in data flow model with testbench
2 : 4 Decoder
2 : 4 Decoder
module
mux4_1decod2_4enco4_2(i0,i1,e,y0,y1,
y2,y3);
input e,i0,i1;
output y0,y1,y2,y3;
assign y3=(e&i1&i0);
assign y2=(e&i1&~i0);
assign y1=(e&~i1&i0);
assign y0=(e&~i1&~i0);
endmodule
////////////////////
module TB_2_4deco_y();
reg e,i0,i1;
wire y0,y1,y2,y3;
mux4_1decod2_4enco4_2 d1(i0,i1,e,y0,y1,y2,y3);
initial
begin
e=0;i0=1;i1=0;
#100;
e=1;i0=0;i1=0;
#100;
e=1;i0=0;i1=1;
#100; e=1;i0=1;i1=0; #100;
e=1;i0=1;i1=1; #100; end
endmodule
mux_4:1
ENCODERS
module encoder_4_2(a,b,c,d,x,y);
output x,y;
input a,b,c,d;
assign x = b | d;
assign y = c | d;
endmodule
module encoder_4_2_test;
reg a,b,c,d;
wire x,y;
encoder_4_2 encoder_4_2_test(a,b,c,d,x,y);
initial
begin
#000 a=0; b=0;c=0;d=1;
#100 a=0; b=0;c=1;d=0;
#100 a=0; b=1;c=0;d=0;
#100 a=1; b=0;c=0;d=0;
end
initial
begin
$monitor($time,"a=%b,b=%b,c=%b,d=%b,x=%b,y=%b",
a,b,c,d,x,y);
end
endmodule
TEST BENCH – D-FLIP FLOP
TEST BENCH:
module dflipflopt_b;
reg d;
D FLIPFLOP reg clk;
module dflipflopmod(q, d, clk);
wire q;
output q;
dflipflopmod uut (.q(q),.d(d), .clk(clk) );
input d;
input clk; initial begin
reg q; // Initialize Inputs
always@(posedge clk) d = 0;
q=d; clk = 0;
endmodule end
always #3 clk=~clk;
always #5 d=~d;
endmodule
124
DEBUGGING AND ERROR CHECKING
125
DEBUGGING AND ERROR CHECKING
module bad_module is(clk,
reset,
[7:0] data_in,
data_out;
carry out,
over_flow )
input clk;
input reset;
input carry_in;
input data_in;
output data_out;
output carry_out;
output over_flow;
reg [7:0] data_out;
reg carry_out, overflow;
126
DEBUGGING AND ERROR CHECKING
over_flow = data_out(7);
end module
127
DEBUGGING AND ERROR CHECKING
module bad_module (clk, (1) Removed “ is” after module
reset,
data_in, (2) Removed [7:0]
carry_in, (3)Added carry_in
data_out, (4) Changed “;” to “ ,”
carry_out, (5) Changed “carry out” to “carry_out”
over_flow ) (6) Semicolon at the end of module definition
input clk;
input reset;
input carry_in;
input [7:0] data_in; (7)Added
output [7:0] data_out; [7:0]
output carry_out; (8)Added
output over_flow; [7:0]
reg [7:0] data_out;
reg carry_out;
128
DEBUGGING AND ERROR CHECKING
always @ (posedge clk or posedge reset) (9) Changed “|” to “ or”
(10)No semicolon for always
if (reset) statement
(11)Added Parentheses around
“ reset”
begin
(12) Removed “ then”
data_out = 0;
(13)Added “begin”
carry_out = 0;
end
else
(14)Added “ end”
begin
data_out = (data_in * 2) + carry_in; ( 1 5 ) “ else” keyword must be lower
case
carry_out = ~& data_in[7:6];
(16)Added “begin”
end
assign over_flow = data_out[7];
(17) Replace “ ,” with “ :”
endmodule
(18)Added “end”
(19) Changed “ out7” to “ out[7]”
(20) Removed space between “ end” & “ module” 129