Multimedia Systems Tutorial
Multimedia Systems Tutorial
Tutorial 2
Instructor: Mr. Bilal Ahmad
In this tutorial you will learn about half adder, subtractor and a four bit adder and subtractor.
After reading the contents you are provided with a Verilog HDL code. It is your responsibility to
learn the content first and then try to understand the code that is in abstract level programming.
1 plus 0 = 12 (110)
and
1 plus 1 = 102 (210)
The half adder is fine for adding two 1-bit numbers together, but for binary numbers containing
several bits, a carry may be produced at some time (as a result of adding 1 and 1) that must be
added to the next column. As the half adder has only two inputs it cannot add in a carry bit from
a previous column, so it is not practical for anything other than 1-bit additions.
Parallel Adders
Even the full adder is only adding two single bit binary numbers, but full adders may be
combined to form parallel adders, which will add two multibit numbers. Parallel adders can be
built in several forms to add multibit binary numbers, each bit of the parallel adder using a
single full adder circuit. As parallel adder circuits would look quite complex if drawn showing
all the individual gates, it is common to replace the full adder schematic diagram with a
simplified block diagram version.
4 Bit Parallel Adder
Fig 4.1.3 illustrates how a number of full adders can be combined to make a parallel adder, also
called a Ripple Carry Adder because of the way that any carry appearing at the carry in input
(CIN) or produced when adding any of the 4-bit inputs, ripples along the adder stages until a
final carry out appears at the carry out output (COUT) of the final full adder for bit A3+B3.
VERILOG CODE:
module adder4bit(s,cout,a,b,cin);
input [3:0] a,b;
input cin;
output [3:0]s;
output cout;
assign {cout,s}=a+b+cin;
endmodule
module addersub(s,cout,a,b,cin);
input [3:0]a,b;
input cin;
output [3:0]s;
output cout;
wire [3:0]f;
assign f[0]=b[0]^cin;
assign f[1]=b[1]^cin;
assign f[2]=b[2]^cin;
assign f[3]=b[3]^cin;
adder4bit ggg(s,cout,a,f,cin);
endmodule
module test;
reg [3:0]a,b;
reg cin;
wire [3:0]s;
wire cout;
addersub hhh(s,cout,a,b,cin);
initial
begin
a=4'd1;b=4'd2;
cin=0;
#10 cin=1'b1;a=4'd3;b=4'd1;
end
initial
$monitor("a=%d,b=%d.......s=%d,cout=%d",a,b,s,cout);
endmodule
Assignment:
Below is the figure given of a universal shift register, you have to write a Verilog HDL Code for
Universal Shift Register