saurab_lab (3)
saurab_lab (3)
Submitted to : Submitted by :
Mr. Nishant Kumar Name : Anjali kumari
(Asst Professor) Branch : CSE(IOT)
Dept. of CSE Reg. No. : 22155154023
INDEX
S.No. Experiment Sign
1 Given a 4-variable logic expression, simplify it using
appropriate technique and simulate the same using
basic gates.
2 Design a 4 bit full adder and subtractor and simulate
the same using basic gates.
3 Design Verilog HDL to implement simple circuits
using structural, Data flow and Behavioural model.
4 Design Verilog HDL to implement Binary Adder-
Subtractor Half and Full Adder, Half and Full
Subtractor.
5 Design Verilog program to implement Different types of
multiplexer like 2:1, 4:1 and 8:1.
6 Design Verilog program for implementing various
types of Flip-Flops such as SR, JK and D.
7 Develop an ALP to multiply two 16-bit binary
numbers.
8 Design Verilog program for implementing various
types of Flip-Flops such as SR, JK and D.
9 Develop an ALP to multiply two 16-bit binary
numbers.
10 Develop an ALP to find the sum of first 10 integer
numbers.
11 Develop an ALP to find the largest/smallest number in
an array of 32 numbers.
12 Develop an ALP to count the number of ones and zeros
in two consecutive memory locations.
1. Simplify a 4-variable logic expression and simulate using
basic gates.
Input: A 4 variable logic Expression, F(A,B,C,D) = ∑ m (2,4,5,7,10,11,14) + d(8,9,12,13,15)
Inputs Output
Decimal
Value A B C D Q
0 0 0 0 0 0
1 0 0 0 1 0
2 0 0 1 0 1
3 0 0 1 1 0
4 0 1 0 0 1
5 0 1 0 1 1
6 0 1 1 0 0
7 0 1 1 1 1
8 1 0 0 0 X
9 1 0 0 1 X
10 1 0 1 0 1
11 1 0 1 1 1
12 1 1 0 0 X
13 1 1 0 1 X
14 1 1 1 0 1
15 1 1 1 1 X
KMAP:
Output:
1. A=0 B=0 C=0 D=0 Then Y=0
Y=AB+CD
Verilog Program :
Structural Gate Level
Data Flow Model Behavioral Model
Model
Output :
1. A=1 B=1 C=1 D=1 Then Y=1
2. A=1 B=0 C=1 D=0 Then Y=0
3.
Design Verilog HDL to implement Binary Adder-Subtractor – Half and Full Adder,
Half and Full Subtractor.
1. Half Adder Design :
Inputs Outputs
Carry Sum
A B
(Cout) (S)
0 0 0 0
0 1 0 1
1 0 0 1
1 1 1 0
S = A ̅ 𝐁 ̅ + 𝐀 ̅ 𝐁 , Cout = A B
Inputs Outputs
0 0 0 0 0
0 0 1 0 1
0 1 0 0 1
0 1 1 1 0
1 0 0 0 1
1 0 1 1 0
1 1 0 1 0
1 1 1 1 1
Kmap
Inputs Outputs
Borrow Difference
X Y (Bout) (D)
0 0 0 0
0 1 1 1
1 0 0 1
1 1 0 0
D = X 𝐘 ̅ + ̅ 𝐗 ̅ 𝐘, Bout = 𝐗 ̅ 𝐘
Inputs Outputs
0 0 0 0 0
0 0 1 1 1
0 1 0 1 1
0 1 1 1 0
1 0 0 0 1
1 0 1 0 0
1 1 0 0 0
Kmap
Simplified Equation for Difference is
D=X Y Bin
Bout = ̅ 𝐗 ̅ 𝐁𝐢𝐧 + Y Bin + ̅ 𝐗 ̅ 𝐘
Output:
FULL ADDER AND SUBTRACTOR VERILOG CODE
module FullAS(a,b,c,sum,car,dif,bw);
input a, b, c;
output sum, car, dif, bw;
Output:
4.
Design a 4 bit full adder and subtractor and simulate the same
using basic gates.
Output:
5. Design Verilog HDL to implement Decimal adder.
module DecimalAdder(A,B,SUM);
input [3:0]A;
input [3:0]B;
output [4:0]SUM;
assign SUM = A + B;
endmodule
Output:
6.
Design Verilog program to implement Different types of multiplexer like 2:1, 4:1
and 8:1.
//8:1 mux
module MUX(S,D,Y);
input [2:0]S;
input [7:0]D;
output Y;
reg Y;
always @ (S or D)
case (S)
0: Y = D[0];
1: Y = D[1];
2: Y = D[2];
3: Y = D[3];
4: Y = D[4];
5: Y = D[5];
6: Y = D[6];
7: Y = D[7];
endcase
endmodule
//4:1 mux
module MUX(S,D,Y);
input [1:0]S;
input [3:0]D;
output Y; reg Y;
always @ (S or D)
case (S)
0: Y = D[0];
1: Y = D[1];
2: Y = D[2];
3: Y = D[3];
endcase
endmodule
`timescale 1ns / 1ps
//2:1 mux
module MUX(S,D,Y);
input [0:0]S;
input [1:0]D;
output Y;
reg Y;
always @ (S or D)
case (S)
0: Y = D[0];
1: Y = D[1];
endcase
endmodule
Output:
2:1 Mux
4:1Mux
8:1 Mux
7.
Design Verilog program to implement types of De-Multiplexer.
module DEMUX(S,D,Y);
input [1:0]S;
input D;
output [3:0]Y;
reg [3:0]Y;
always @ (S or D)
begin
Y[3:0] = 0;
case (S)
0: Y[0] = D;
1: Y[1] = D;
2: Y[2] = D;
3: Y[3] = D;
endcase
end
endmodule
Output:
8.
Design Verilog program for implementing various types of Flip-Flops such
as SR, JK and D
D Flip Flop:
module DFF(D,Q,QB,CLK,RST);
input D, CLK, RST;
output Q, QB;
reg Q, QB;
always @(posedge CLK)
begin
if(RST) Q <= 0; // for synchronous reset
else
begin
case(D)
0: Q <= 0;
1: Q <= 1;
endcase
end
assign QB = ~Q;
end
endmodule
SR Flip Flop:
module SRFF(S,R,Q,QB,CLK,RST);
input S, R, CLK, RST;
output Q, QB;
reg Q, QB;
always @(posedge CLK)
begin
if(RST) Q <= 0; // for synchronous reset
else
begin
case({S,R})
2'b00: Q <= Q; // No change
2'b01: Q <= 0;
2'b10: Q <= 1;
2'b11: Q <= 1'bx; // Invalid
endcase
end
assign QB = ~Q;
end
endmodule
JK Flipflop:
module JKFF(J,K,Q,QB,CLK,RST);
input J, K, CLK, RST;
output Q, QB;
reg Q, QB;
always @(posedge CLK)
begin
if(RST) Q <= 0; // for synchronous reset
else
begin
case({J,K})
2'b00: Q <= Q; // No change
2'b01: Q <= 0;
2'b10: Q <= 1;
2'b11: Q <= ~Q; // Toggle
endcase
end
assign QB = ~Q;
end
endmodule
Output:
JK FLIP-FLOP
SR FLIP-FLOP
D FLIP-FLOP
9. Develop an ALP to multiply two 16-bit binary
numbers.
Output :
10.
Develop an ALP to find the sum of first 10
integer numbers.
AREA SUM10, CODE, READONLY
ENTRY ; Define the entry point of the program
START ; Label for the start of the program
MOV r0,#10 ; Initialize register r0 with the value 10
MOV r1,r0 ; Copy the value of r0 to r1 (r1 = 10)
RPT ; Label for the start of the loop
SUBS r1,r1,#1 ; Decrement r1 by 1 (r1 = r1 - 1) and set flags
CMP r1,#0 ; Compare r1 with 0
BEQ STOP ; If r1 is equal to 0, branch to the STOP label
ADD r3,r0,r1 ; Add the values of r0 and r1 and store the result in r3
MOV r0,r3 ; Update r0 with the new sum (r0 = r3)
BNE RPT ; If the result of the subtraction (r1 - 1) is not zero, branch back
to RPT
NOP ; No operation (do nothing)
NOP
STOP
END ; End of the program
Output :
Output :
12.
Develop an ALP to find the largest/smallest
number in an array of 32 numbers.
1) SMALLEST:
AREA SMALLEST, CODE,READONLY
ENTRY ; Define the entry point of the program
START ; Label for the start of the program
MOV R5,#6 ; Initialize register R5 with the value 6
(number of elements in the array)
LDR R1,=VALUE1 ; Load the address of the VALUE1 array into
register R1
LDR R2,[R1],#4 ; Load the first element of the array into
register R2 (initial smallest value)
LOOP ; Label for the start of the loop
LDR R4,[R1],#4 ; Load the next element of the array into
register R4
CMP R2,R4 ; Compare the current smallest value (R2) with the
new value (R4)
BLS LOOP1 ; If the new value is smaller, branch to LOOP1
(update smallest value)
MOV R2,R4 ; Update the smallest value (R2) with the new
value (R4)
LOOP1 ; Label for the continuation of the loop
SUBS R5,R5,#1 ; Decrement the counter (R5) by 1 and set
flags
CMP R5,#0 ; Compare the counter (R5) with 0
BNE LOOP ; If the counter is not zero, branch back to LOOP
(loop until all elements are
processed)
LDR R4,=RESULT ; Load the address of the RESULT variable
into register R4
STR R2,[R4] ; Store the smallest value (R2) into the RESULT
variable
BACK B BACK ; Infinite loop to prevent the program from
terminating (not necessary in
this case)
MEMORY:-
*Memory before execution:
*Memory after execution :
2) LARGEST:
AREA LARGEST, CODE,READONLY
ENTRY ; Define the entry point of the program
START ; Label for the start of the program
MOV R5,#6 ; Initialize register R5 with the value 6 (number of
elements in the array)
LDR R1,=VALUE1 ; Load the address of the VALUE1 array into
register R1
LDR R2,[R1],#4 ; Load the first element of the array into register R2
(initial smallest value)
LOOP ; Label for the start of the loop
LDR R4,[R1],#4 ; Load the next element of the array into register R4
CMP R2,R4 ; Compare the current smallest value (R2) with the new
value (R4)
BHI LOOP1 ; If the new value is higher, branch to LOOP1 (update
largest value)
MOV R2,R4 ; Update the smallest value (R2) with the new value (R4)
LOOP1 ; Label for the continuation of the loop
SUBS R5,R5,#1 ; Decrement the counter (R5) by 1 and set flags
CMP R5,#0 ; Compare the counter (R5) with 0
BNE LOOP ; If the counter is not zero, branch back to LOOP (loop
until all elements are
processed)
LDR R4,=RESULT ; Load the address of the RESULT variable into
register R4
STR R2,[R4] ; Store the smallest value (R2) into the RESULT
variable
BACK B BACK ; Infinite loop to prevent the program from terminating (not
necessary in this case)