Skip to content

Commit 44a11c2

Browse files
committed
Merge pull request #640 from a-rey/gh-pages
adding system verilog language
2 parents 7feb135 + 1cf5006 commit 44a11c2

File tree

4 files changed

+126
-0
lines changed

4 files changed

+126
-0
lines changed

components.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,10 @@ var components = {
438438
"require": "javascript",
439439
"owner": "vkbansal"
440440
},
441+
"verilog": {
442+
"title": "Verilog & System Verilog",
443+
"owner": "a-rey"
444+
},
441445
"vhdl": {
442446
"title": "VHDL",
443447
"owner": "a-rey"

components/prism-verilog.js

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/prism-verilog.min.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/prism-verilog.html

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<h1>Verilog &amp; System Verilog</h1>
2+
<p>To use this language, use the class "language-verilog". Note that this package supports syntax highlighting for both Verilog and System Verilog.</p>
3+
4+
<h2>Comments</h2>
5+
<pre><code>/* Multiline comments in Verilog
6+
look like C comments and // is OK in here. */
7+
// Single-line comment in Verilog.</code></pre>
8+
9+
<h2>Literals</h2>
10+
<pre><code>// example code from: http://iroi.seu.edu.cn/books/asics/Book2/CH11/CH11.02.htm
11+
module declarations;
12+
parameter H12_UNSIZED = 'h 12;
13+
parameter H12_SIZED = 6'h 12;
14+
parameter D42 = 8'B0010_1010;
15+
parameter D123 = 123;
16+
parameter D63 = 8'o 77;
17+
parameter A = 'h x, B = 'o x, C = 8'b x, D = 'h z, E = 16'h ????;
18+
reg [3:0] B0011,Bxxx1,Bzzz1;
19+
real R1,R2,R3;
20+
integer I1,I3,I_3;
21+
parameter BXZ = 8'b1x0x1z0z;
22+
23+
initial begin
24+
B0011 = 4'b11; Bxxx1 = 4'bx1; Bzzz1 = 4'bz1;
25+
R1 = 0.1e1; R2 = 2.0; R3 = 30E-01;
26+
I1 = 1.1; I3 = 2.5; I_3 = -2.5;
27+
end
28+
29+
initial begin #1;
30+
$display("H12_UNSIZED, H12_SIZED (hex) = %h, %h",H12_UNSIZED, H12_SIZED);
31+
$display("D42 (bin) = %b",D42," (dec) = %d",D42);
32+
$display("D123 (hex) = %h",D123," (dec) = %d",D123);
33+
$display("D63 (oct) = %o",D63);
34+
$display("A (hex) = %h",A," B (hex) = %h",B);
35+
$display("C (hex) = %h",C," D (hex) = %h",D," E (hex) = %h",E);
36+
$display("BXZ (bin) = %b",BXZ," (hex) = %h",BXZ);
37+
$display("B0011, Bxxx1, Bzzz1 (bin) = %b, %b, %b",B0011,Bxxx1,Bzzz1);
38+
$display("R1, R2, R3 (e, f, g) = %e, %f, %g", R1, R2, R3);
39+
$display("I1, I3, I_3 (d) = %d, %d, %d", I1, I3, I_3);
40+
end
41+
endmodule</code></pre>
42+
43+
<h2>Full example</h2>
44+
<pre><code>`include "internal_defines.vh"
45+
46+
//*****************************************************************************
47+
// memory_decoder: a custom module used to handle memory transactions
48+
//*****************************************************************************
49+
//
50+
// out_mem (output) - The output to memory
51+
// out_reg (output) - The output to the register file
52+
// mem_we (output) - Which byte in the word to write too
53+
// mem_in (input) - The input from memory
54+
// addr_in (input) - The lowest 2 bits of byte offset to store in memory
55+
// data_in (input) - The input from the register file to be stored
56+
// l_bit (input) - The load bit signal (control)
57+
// b_bit (input) - The byte bit signal (control)
58+
//
59+
module memory_decoder(out_mem, out_reg, mem_in, data_in, l_bit, b_bit, addr_in,
60+
mem_we);
61+
62+
output reg [31:0] out_mem, out_reg;
63+
output reg [3:0] mem_we;
64+
input [31:0] mem_in, data_in;
65+
input [1:0] addr_in;
66+
input l_bit, b_bit;
67+
68+
always_comb begin
69+
mem_we = 4'b0000; // dont write memory by default
70+
if (l_bit == 1) begin // ldr and ldrb
71+
out_mem = mem_in; // dont change memory!
72+
if (b_bit == 1) begin
73+
/* figure out which byte to load from memory */
74+
case (addr_in)
75+
2'b00: out_reg = {24'b00, mem_in[7:0]};
76+
2'b01: out_reg = {24'b00, mem_in[15:8]};
77+
2'b10: out_reg = {24'b00, mem_in[23:16]};
78+
2'b11: out_reg = {24'b00, mem_in[31:24]};
79+
endcase
80+
end
81+
else begin
82+
out_reg = mem_in;
83+
end
84+
end
85+
else begin // str and strb
86+
out_reg = `UNKNOWN; // We are not reading from mem
87+
if (b_bit == 1) begin
88+
/* figure out which byte to write to in memory */
89+
out_mem = {4{data_in[7:0]}};
90+
case (addr_in)
91+
2'b00: mem_we = 4'b1000;
92+
2'b01: mem_we = 4'b0100;
93+
2'b10: mem_we = 4'b0010;
94+
2'b11: mem_we = 4'b0001;
95+
endcase
96+
end
97+
else begin
98+
mem_we = 4'b1111; // write to all channels
99+
out_mem = data_in;
100+
end
101+
end
102+
end
103+
104+
endmodule</code></pre>

0 commit comments

Comments
 (0)