Laborator 3
Problema 1
Proiectati, utilizand Verilog, un model care selecteaza , dependent de o intrare switch cei mai semnificativi 16 biti ai intrarii i sau cei mai putini semnificativi ai intrarii i. Intrarea i are 24 biti, iar iesirea se numeste o.
Problema 2
Construiti, utilizand Verilog, un model care calculeaza rezultatul inmultirii cu 16 a numarului pe 8 biti de la intrare, fara a utiliza operatorul de deplasare Verilog "<<".
Problema 3
Implementati, utilizand Verilog, un modul pentru testarea valorii 0 a unui numar reprezentat in Semn Marime pe 8 biti, fara a folosi operatorul relational "==".
Rezolvare problema 1
module select(input switch,
input [23:0]i,
output [15:0]o);
assign o = switch ? i[23:8] : i[15:0];
endmodule
module select_tb();
reg switch;
reg [23:0]i;
wire [15:0]o;
integer j;
select uut(
.switch(switch),
.i(i),
.o(o));
initial begin
switch = 0;
i = 1;
#5 $monitor("%b - %b -> %b\n", i, switch, o);
end
always begin
for(j=0;j<8;j=j+1) begin
#5 switch = ~switch;
#5 i = i + 2048;
end
$finish;
end
endmodule
Rezolvare problema 2
module times16(input [7:0]i,
output [11:0]o);
assign o = {i, 4'b0000}; //numar binar de 4 biti
endmodule
module times16_tb ();
reg [7:0]i;
wire [11:0]o;
integer j;
times16 uut(.i(i), .o(o));
initial begin
i = 0;
#5 $monitor("%b -> %b\n", i, o);
end
always begin
for(j=0;j<8;j=j+1) begin
#5 i = i + 1;
end
$finish;
end
endmodule
Rezolvare problema 3
module is_zero(input [7:0]i,
output o);
assign o = ~(|i[6:0]); // verificam toti bitii, mai putin cel de semn
endmodule
module is_zero_tb();
reg [7:0]i;
wire o;
integer j;
is_zero uut(.i(i), .o(o));
initial begin
i = 0;
#5 $monitor("%b -> %b\n", i, o);
end
always begin
for(j=0;j<8;j++) begin
#5 i = i + 32;
end
$finish;
end
endmodule