Skip to content

Commit 30246e6

Browse files
committed
Added Verilog Programming Language
1 parent 65e07f9 commit 30246e6

File tree

4 files changed

+68
-0
lines changed

4 files changed

+68
-0
lines changed

verilog/clockhands.sv

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
module ClockHands;
2+
integer i, t, h, m, s;
3+
function reg [1:2*8] pad;
4+
input integer n;
5+
reg [1:2*8] format;
6+
begin
7+
format[1:8] = n / 10 + 48;
8+
format[9:16] = n % 10 + 48;
9+
pad = format;
10+
end
11+
endfunction
12+
13+
initial begin
14+
for (i = 0 ; i < 11 ; i++) begin
15+
t = (43200 * i + 21600) / 11;
16+
h = t / 3600;
17+
m = t / 60 % 60;
18+
s = t % 60;
19+
$display("%s:%s:%s", pad(h ? h : 12), pad(m), pad(s));
20+
end
21+
end
22+
endmodule

verilog/hello.sv

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module HelloWorld;
2+
initial
3+
$display("Hello, world!");
4+
endmodule

verilog/test.ps1

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
function Assert-MatchTests {
2+
param (
3+
[Parameter(Mandatory = $true, ValueFromPipeline)] $TestResult
4+
)
5+
6+
if ($TestResult) {
7+
Write-Error "Output does not match expected results."
8+
}
9+
}
10+
11+
$bin = "$PSScriptRoot\bin"
12+
13+
# First check if folder bin exists. If not, make a new bin folder.
14+
if (!(Test-Path -Path $bin)) {
15+
New-Item -Path $bin -Type Directory
16+
}
17+
18+
$Error.clear()
19+
iverilog -o "$bin\clockhands" "$PSScriptRoot\clockhands.sv" && vvp "$bin\clockhands" |
20+
Compare-Object (Get-Content "$PSScriptRoot\..\test\clockhands_expected") |
21+
Assert-MatchTests &&
22+
iverilog -o "$bin\hello" "$PSScriptRoot\hello.sv" && vvp "$bin\hello" &&
23+
iverilog -o "$bin\triple" "$PSScriptRoot\triple.sv" && vvp "$bin\triple" |
24+
Compare-Object (Get-Content "$PSScriptRoot\..\test\triple_expected") |
25+
Assert-MatchTests &&
26+
ForEach-Object 'foo'
27+
28+
if ($Error -or !$?) {
29+
"*** VERILOG TESTS FAILED ***"
30+
}
31+
else {
32+
"VERILOG TESTS PASSED"
33+
}

verilog/triple.sv

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module Triple;
2+
integer a, b, c;
3+
initial
4+
for (c = 1 ; c < 41 ; c++)
5+
for (b = 1 ; b < c ; b++)
6+
for (a = 1 ; a < b ; a++)
7+
if (a * a + b * b == c * c)
8+
$display("%0d, %0d, %0d", a, b, c);
9+
endmodule

0 commit comments

Comments
 (0)