Sunteți pe pagina 1din 2

Laborator 2

1. Să se modeleze în Verilog HDL logica combinațională corespunzătoare funcției:


f(x3,x2,x1,x0) = R1(0, 2, 4, 5, 7, 11, 13);
și să se scrie un modul de test pentru modelul realizat.

Rezolvare:

module f(x3, x2, x1, x0, z);


input x3, x2, x1, x0;
output z;

assign z = ((~x3)&&(~x2)&&(~x1)&&(~x0))||
((~x3)&&(~x2)&&x1&&(~x0))||
((~x3)&&x2&&(~x1)&&(~x0))||
((~x3)&&x2&&(~x1)&&x0)||
((~x3)&&x2&&x1&&x0)||
(x3&&(~x2)&&x1&&x0)||
(x3&&x2&&(~x1)&&x0);
endmodule

Modulul de test:

module test_f;
reg x3t, x2t, x1t, x0t;
wire zt;

f f_inst( .x3(x3t), .x2(x2t), .x1(x1t), .x0(x0t), .z(zt));

initial
begin
#0 {x3t,x2t,x1t,x0t} = 4’d0;
#10 {x3t,x2t,x1t,x0t} = 4’d4;
#10 {x3t,x2t,x1t,x0t} = 4’d9;
#10 {x3t,x2t,x1t,x0t} = 4’d12;
#10 {x3t,x2t,x1t,x0t} = 4’d13;
#10 {x3t,x2t,x1t,x0t} = 4’d15;
..........................................
end
initial
#200 $finish;
endmodule

2. Să se modeleze în Verilog HDL logica combinațională corespunzătoare funcției:


f(x3,x2,x1,x0) = R0(0, 1, 3, 8, 9, 12, 15);
și să se scrie un modul de test pentru modelul realizat.
3. Să se modeleze în Verilog HDL un bistabil flip-flop de tip D, cu intrare de reset și
cu intrare de condiționare a încărcării, ambele sincrone, active pe 1 logic. Să se
scrie un modul de test pentru modelul realizat.

Rezolvare:

module dff_reset_load(clk, reset, load, d, q);


input clk, reset, load, d;
output reg q;

always @(posedge clk)


if(reset)
q <= 1’b0;
else
if(load)
q <= d;
endmodule

Modulul de test:

module test_dff_reset_load;
reg clkt, resett, loadt, dt;
wire qt;

dff_reset_load dff_reset_load_inst( .clk(clkt), .reset(resett),


.load(loadt), .d(dt), .q(qt));

initial
begin
#0 clkt = 1’b0;
forever #5 clkt = ~clkt;
end

initial
begin
#0 resett = 1’b1; dt = 1’b1; loadt = 1’b0;
#10 resett = 1’b0;
#10 loadt = 1’b1;
…………………………………………..
end

initial
#200 $finish;
endmodule

4. Folosind modelul de bistabil flip-flop D cu reset și load sincrone și active pe 1 logic


dezvoltat la 3. să se realizeze modelul unui registru de 8 biți cu reset și parallel
load sincrone, active pe 1 logic. Să se scrie un modul de test pentru modelul
realizat.

S-ar putea să vă placă și