first commit

This commit is contained in:
2026-11-24 22:49:06 +01:00
commit 20a1830bc6
10 changed files with 872 additions and 0 deletions
+21
View File
@@ -0,0 +1,21 @@
module shift_reg_4b (
input logic clk,
input logic rst,
input logic en,
input logic in,
output logic out
);
logic [3:0] shift_reg;
always_ff @(posedge clk) begin
if (rst) begin
shift_reg <= 4'b0000;
end else if (en) begin
shift_reg <= {shift_reg[2:0], in};
end
end
assign out = shift_reg[3];
endmodule
+172
View File
@@ -0,0 +1,172 @@
$date
Tue Nov 24 22:08:34 2026
$end
$version
Icarus Verilog
$end
$timescale
1ps
$end
$scope module tb_shift_reg_4b $end
$var wire 1 ! out $end
$var reg 1 " clk $end
$var reg 1 # en $end
$var reg 1 $ in $end
$var reg 1 % rst $end
$scope module dut $end
$var wire 1 " clk $end
$var wire 1 # en $end
$var wire 1 $ in $end
$var wire 1 % rst $end
$var wire 1 ! out $end
$var reg 4 & shift_reg [3:0] $end
$upscope $end
$upscope $end
$enddefinitions $end
$comment Show the parameter values. $end
$dumpall
$end
#0
$dumpvars
bx &
1%
0$
0#
0"
x!
$end
#5000
0!
b0 &
1"
#10000
0"
#15000
1"
#20000
0"
#25000
1$
1#
0%
1"
#30000
0"
#35000
0$
b1 &
1"
#40000
0"
#45000
b10 &
1"
#50000
0"
#55000
b100 &
1"
#60000
0"
#65000
1!
b1000 &
1"
#70000
0"
#75000
0!
b0 &
1"
#80000
0"
#85000
1$
1"
#90000
0"
#95000
0$
b1 &
1"
#100000
0"
#105000
b10 &
1$
1"
#110000
0"
#115000
b101 &
1"
#120000
0"
#125000
1!
b1011 &
0$
1"
#130000
0"
#135000
0!
0#
b110 &
1"
#140000
0"
#145000
1"
#150000
0"
#155000
1"
#160000
0"
#165000
1#
1"
#170000
0"
#175000
1!
b1100 &
1"
#180000
0"
#185000
b1000 &
1"
#190000
0"
#195000
0!
b0 &
1"
#200000
0"
#205000
1"
#210000
0"
#215000
1%
1"
#220000
0"
#225000
1"
#230000
0"
#235000
0%
1"
#240000
0"
#245000
1"
#250000
0"
#255000
1"
+165
View File
@@ -0,0 +1,165 @@
#! /c/Source/iverilog-install/bin/vvp
:ivl_version "14.0 (devel)";
:ivl_delay_selection "TYPICAL";
:vpi_time_precision - 12;
:vpi_module "C:\iverilog\lib\ivl\system.vpi";
:vpi_module "C:\iverilog\lib\ivl\vhdl_sys.vpi";
:vpi_module "C:\iverilog\lib\ivl\vhdl_textio.vpi";
:vpi_module "C:\iverilog\lib\ivl\v2005_math.vpi";
:vpi_module "C:\iverilog\lib\ivl\va_math.vpi";
:vpi_module "C:\iverilog\lib\ivl\v2009.vpi";
S_000001946E405540 .scope package, "$unit" "$unit" 2 1;
.timescale 0 0;
S_000001946E405120 .scope module, "tb_shift_reg_4b" "tb_shift_reg_4b" 3 3;
.timescale -9 -12;
v000001946E406F50_0 .var "clk", 0 0;
v000001946E4074F0_0 .var "en", 0 0;
v000001946E406D70_0 .var "in", 0 0;
v000001946E406FF0_0 .net "out", 0 0, L_000001946E406EB0; 1 drivers
v000001946E4071D0_0 .var "rst", 0 0;
S_000001946E407C90 .scope module, "dut" "shift_reg_4b" 3 13, 4 1 0, S_000001946E405120;
.timescale 0 0;
.port_info 0 /INPUT 1 "clk";
.port_info 1 /INPUT 1 "rst";
.port_info 2 /INPUT 1 "en";
.port_info 3 /INPUT 1 "in";
.port_info 4 /OUTPUT 1 "out";
v000001946E407810_0 .net "clk", 0 0, v000001946E406F50_0; 1 drivers
v000001946E4076D0_0 .net "en", 0 0, v000001946E4074F0_0; 1 drivers
v000001946E4078B0_0 .net "in", 0 0, v000001946E406D70_0; 1 drivers
v000001946E407130_0 .net "out", 0 0, L_000001946E406EB0; alias, 1 drivers
v000001946E407270_0 .net "rst", 0 0, v000001946E4071D0_0; 1 drivers
v000001946E406E10_0 .var "shift_reg", 3 0;
E_000001946E421570 .event posedge, v000001946E407810_0;
L_000001946E406EB0 .part v000001946E406E10_0, 3, 1;
.scope S_000001946E407C90;
T_0 ;
%wait E_000001946E421570;
%load/vec4 v000001946E407270_0;
%flag_set/vec4 8;
%jmp/0xz T_0.0, 8;
%pushi/vec4 0, 0, 4;
%assign/vec4 v000001946E406E10_0, 0;
%jmp T_0.1;
T_0.0 ;
%load/vec4 v000001946E4076D0_0;
%flag_set/vec4 8;
%jmp/0xz T_0.2, 8;
%load/vec4 v000001946E406E10_0;
%parti/s 3, 0, 2;
%load/vec4 v000001946E4078B0_0;
%concat/vec4; draw_concat_vec4
%assign/vec4 v000001946E406E10_0, 0;
T_0.2 ;
T_0.1 ;
%jmp T_0;
.thread T_0;
.scope S_000001946E405120;
T_1 ;
%pushi/vec4 0, 0, 1;
%store/vec4 v000001946E406F50_0, 0, 1;
T_1.0 ;
%delay 5000, 0;
%load/vec4 v000001946E406F50_0;
%inv;
%store/vec4 v000001946E406F50_0, 0, 1;
%jmp T_1.0;
T_1.1 ;
%end;
.thread T_1;
.scope S_000001946E405120;
T_2 ;
%vpi_call/w 3 30 "$dumpfile", "shift_reg_4b.vcd" {0 0 0};
%vpi_call/w 3 31 "$dumpvars", 32'sb00000000000000000000000000000000, S_000001946E405120 {0 0 0};
%pushi/vec4 1, 0, 1;
%store/vec4 v000001946E4071D0_0, 0, 1;
%pushi/vec4 0, 0, 1;
%store/vec4 v000001946E4074F0_0, 0, 1;
%pushi/vec4 0, 0, 1;
%store/vec4 v000001946E406D70_0, 0, 1;
%delay 20000, 0;
%wait E_000001946E421570;
%pushi/vec4 0, 0, 1;
%assign/vec4 v000001946E4071D0_0, 0;
%pushi/vec4 1, 0, 1;
%assign/vec4 v000001946E4074F0_0, 0;
%pushi/vec4 1, 0, 1;
%assign/vec4 v000001946E406D70_0, 0;
%wait E_000001946E421570;
%pushi/vec4 0, 0, 1;
%assign/vec4 v000001946E406D70_0, 0;
%pushi/vec4 5, 0, 32;
T_2.0 %dup/vec4;
%cmpi/s 0, 0, 32;
%jmp/1xz T_2.1, 5;
%jmp/1 T_2.1, 4;
%subi 1, 0, 32;
%wait E_000001946E421570;
%jmp T_2.0;
T_2.1 ;
%pop/vec4 1;
%pushi/vec4 1, 0, 1;
%assign/vec4 v000001946E406D70_0, 0;
%wait E_000001946E421570;
%pushi/vec4 0, 0, 1;
%assign/vec4 v000001946E406D70_0, 0;
%wait E_000001946E421570;
%pushi/vec4 1, 0, 1;
%assign/vec4 v000001946E406D70_0, 0;
%wait E_000001946E421570;
%pushi/vec4 1, 0, 1;
%assign/vec4 v000001946E406D70_0, 0;
%wait E_000001946E421570;
%pushi/vec4 0, 0, 1;
%assign/vec4 v000001946E406D70_0, 0;
%wait E_000001946E421570;
%pushi/vec4 0, 0, 1;
%assign/vec4 v000001946E4074F0_0, 0;
%pushi/vec4 3, 0, 32;
T_2.2 %dup/vec4;
%cmpi/s 0, 0, 32;
%jmp/1xz T_2.3, 5;
%jmp/1 T_2.3, 4;
%subi 1, 0, 32;
%wait E_000001946E421570;
%jmp T_2.2;
T_2.3 ;
%pop/vec4 1;
%pushi/vec4 1, 0, 1;
%assign/vec4 v000001946E4074F0_0, 0;
%pushi/vec4 5, 0, 32;
T_2.4 %dup/vec4;
%cmpi/s 0, 0, 32;
%jmp/1xz T_2.5, 5;
%jmp/1 T_2.5, 4;
%subi 1, 0, 32;
%wait E_000001946E421570;
%jmp T_2.4;
T_2.5 ;
%pop/vec4 1;
%pushi/vec4 1, 0, 1;
%assign/vec4 v000001946E4071D0_0, 0;
%pushi/vec4 2, 0, 32;
T_2.6 %dup/vec4;
%cmpi/s 0, 0, 32;
%jmp/1xz T_2.7, 5;
%jmp/1 T_2.7, 4;
%subi 1, 0, 32;
%wait E_000001946E421570;
%jmp T_2.6;
T_2.7 ;
%pop/vec4 1;
%pushi/vec4 0, 0, 1;
%assign/vec4 v000001946E4071D0_0, 0;
%delay 20000, 0;
%vpi_call/w 3 74 "$display", "Fin de la simulation." {0 0 0};
%vpi_call/w 3 75 "$finish" {0 0 0};
%end;
.thread T_2;
# The file index is used to find the file name in the following table.
:file_names 5;
"N/A";
"<interactive>";
"-";
"tb_shift_reg_4b.sv";
"shift_reg_4b.sv";
+78
View File
@@ -0,0 +1,78 @@
`timescale 1ns / 1ps
module tb_shift_reg_4b;
// Signaux de test reliés au module (DUT : Device Under Test)
logic clk;
logic rst;
logic en;
logic in;
logic out;
// Instanciation du registre à décalage 4 bits
shift_reg_4b dut (
.clk(clk),
.rst(rst),
.en(en),
.in(in),
.out(out)
);
// Génération de l'horloge : période de 10 ns (100 MHz)
initial begin
clk = 1'b0;
forever #5 clk = ~clk;
end
// Scénario de stimulation
initial begin
// Configuration pour l'export des chronogrammes (Icarus Verilog / GTKWave)
$dumpfile("shift_reg_4b.vcd");
$dumpvars(0, tb_shift_reg_4b);
// 1. Initialisation et Reset actif
rst = 1'b1;
en = 1'b0;
in = 1'b0;
#20; // Maintien du reset pendant 2 coups d'horloge
// 2. Relâchement du reset et activation (en = 1)
@(posedge clk);
rst <= 1'b0;
en <= 1'b1;
// 3. Injection d'une impulsion '1' d'un coup d'horloge
// Elle doit ressortir sur 'out' exactement 4 coups d'horloge plus tard
in <= 1'b1;
@(posedge clk);
in <= 1'b0;
// Attente de 5 coups d'horloge pour observer la sortie
repeat (5) @(posedge clk);
// 4. Test d'une séquence de bits : 1 -> 0 -> 1 -> 1
in <= 1'b1; @(posedge clk);
in <= 1'b0; @(posedge clk);
in <= 1'b1; @(posedge clk);
in <= 1'b1; @(posedge clk);
in <= 1'b0;
// 5. Test du gel via 'en = 0' en plein milieu du décalage
@(posedge clk);
en <= 1'b0; // Le registre doit conserver son état
repeat (3) @(posedge clk);
en <= 1'b1; // Reprise du décalage
repeat (5) @(posedge clk);
// 6. Test d'un reset en cours de fonctionnement
rst <= 1'b1;
repeat (2) @(posedge clk);
rst <= 1'b0;
#20;
$display("Fin de la simulation.");
$finish;
end
endmodule