Last active
August 29, 2015 13:59
-
-
Save nootanghimire/10746145 to your computer and use it in GitHub Desktop.
Some Basic Verilog Learnings
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module main; | |
| reg a, b, Cin; | |
| wire S, Cout; | |
| fulladder f1(a,b,Cin,S,Cout); | |
| initial | |
| begin | |
| a=1'b0;b=1'b0;Cin=1'b0; | |
| #40 | |
| $display("0 0 0"); | |
| $display("Sum: "); | |
| $display(S); | |
| $display("CarryOut: "); | |
| $display(Cout); | |
| $display(""); | |
| a=1'b0;b=1'b0;Cin=1'b1; | |
| #40 | |
| $display("0 0 1"); | |
| $display("Sum: "); | |
| $display(S); | |
| $display("CarryOut: "); | |
| $display(Cout); | |
| $display(""); | |
| a=1'b0;b=1'b1;Cin=1'b0; | |
| #40 | |
| $display("0 1 0"); | |
| $display("Sum: "); | |
| $display(S); | |
| $display("CarryOut: "); | |
| $display(Cout); | |
| $display(""); | |
| a=1'b0;b=1'b1;Cin=1'b1; | |
| #40 | |
| $display("0 1 1"); | |
| $display("Sum: "); | |
| $display(S); | |
| $display("CarryOut: "); | |
| $display(Cout); | |
| $display(""); | |
| a=1'b1;b=1'b0;Cin=1'b0; | |
| #40 | |
| $display("1 0 0"); | |
| $display("Sum: "); | |
| $display(S); | |
| $display("CarryOut: "); | |
| $display(Cout); | |
| $display(""); | |
| a=1'b1;b=1'b0;Cin=1'b1; | |
| #40 | |
| $display("1 0 1"); | |
| $display("Sum: "); | |
| $display(S); | |
| $display("CarryOut: "); | |
| $display(Cout); | |
| $display(""); | |
| a=1'b1;b=1'b1;Cin=1'b0; | |
| #40 | |
| $display("1 1 0"); | |
| $display("Sum: "); | |
| $display(S); | |
| $display("CarryOut: "); | |
| $display(Cout); | |
| $display(""); | |
| a=1'b1;b=1'b1;Cin=1'b1; | |
| #40 | |
| $display("1 1 1"); | |
| $display("Sum: "); | |
| $display(S); | |
| $display("CarryOut: "); | |
| $display(Cout); | |
| $display(""); | |
| end | |
| endmodule | |
| module fulladder(A, B, cIN, s, cOUT); | |
| input A,B, cIN; | |
| output s, cOUT; | |
| wire a1, a2, x1; | |
| xor x1(s,A,B,cIN); | |
| and and1(a1, A, B); | |
| xor xo1(x1, A, B); | |
| and and2(a2, x1, cIN); | |
| or o1(cOUT, a1, a2); | |
| endmoduleadd |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module main; | |
| reg a, b, Cin; | |
| wire S, Cout; | |
| fulladder f1(a,b,Cin,S,Cout); | |
| initial | |
| begin | |
| a=1'b0;b=1'b0;Cin=1'b0; | |
| #40 | |
| $display("0 0 0"); | |
| $display("Sum: "); | |
| $display(S); | |
| $display("CarryOut: "); | |
| $display(Cout); | |
| $display(""); | |
| a=1'b0;b=1'b0;Cin=1'b1; | |
| #40 | |
| $display("0 0 1"); | |
| $display("Sum: "); | |
| $display(S); | |
| $display("CarryOut: "); | |
| $display(Cout); | |
| $display(""); | |
| a=1'b0;b=1'b1;Cin=1'b0; | |
| #40 | |
| $display("0 1 0"); | |
| $display("Sum: "); | |
| $display(S); | |
| $display("CarryOut: "); | |
| $display(Cout); | |
| $display(""); | |
| a=1'b0;b=1'b1;Cin=1'b1; | |
| #40 | |
| $display("0 1 1"); | |
| $display("Sum: "); | |
| $display(S); | |
| $display("CarryOut: "); | |
| $display(Cout); | |
| $display(""); | |
| a=1'b1;b=1'b0;Cin=1'b0; | |
| #40 | |
| $display("1 0 0"); | |
| $display("Sum: "); | |
| $display(S); | |
| $display("CarryOut: "); | |
| $display(Cout); | |
| $display(""); | |
| a=1'b1;b=1'b0;Cin=1'b1; | |
| #40 | |
| $display("1 0 1"); | |
| $display("Sum: "); | |
| $display(S); | |
| $display("CarryOut: "); | |
| $display(Cout); | |
| $display(""); | |
| a=1'b1;b=1'b1;Cin=1'b0; | |
| #40 | |
| $display("1 1 0"); | |
| $display("Sum: "); | |
| $display(S); | |
| $display("CarryOut: "); | |
| $display(Cout); | |
| $display(""); | |
| a=1'b1;b=1'b1;Cin=1'b1; | |
| #40 | |
| $display("1 1 1"); | |
| $display("Sum: "); | |
| $display(S); | |
| $display("CarryOut: "); | |
| $display(Cout); | |
| $display(""); | |
| end | |
| endmodule | |
| module fulladder(A, B, cIN, s, cOUT); | |
| input A,B, cIN; | |
| output s, cOUT; | |
| assign s = A^B^cIN; | |
| assign cOUT = (A&B)|((A^B)&cIN); | |
| endmodule |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module main; | |
| reg a,b; | |
| wire s,c; | |
| fulladdr f1(a,b,s,c); | |
| reg s1,s2,dl; | |
| wire o1, o2, o3, o4; | |
| demux1_4 d1(s1,s2,dl,o1,o2,o3,o4); | |
| initial | |
| begin | |
| a=1'b0;b=1'b0; | |
| #20 | |
| $display("Sum: "); | |
| $display(s); | |
| $display("Carry: "); | |
| $display(c); | |
| a=1'b0;b=1'b1; | |
| #20 | |
| $display("Sum: "); | |
| $display(s); | |
| $display("Carry: "); | |
| $display(c); | |
| a=1'b1;b=1'b0; | |
| #20 | |
| $display("Sum: "); | |
| $display(s); | |
| $display("Carry: "); | |
| $display(c); | |
| a=1'b1;b=1'b1; | |
| #20 | |
| $display("Sum: "); | |
| $display(s); | |
| $display("Carry: "); | |
| $display(c); | |
| $display(""); | |
| $display("-- Next --"); | |
| $display(""); | |
| dl = 1'b1; | |
| s1=1'b0;s2=1'b0; | |
| #20 | |
| $display(""); | |
| $display("0"); | |
| $display(""); | |
| $display("o1: "); | |
| $display(o1); | |
| $display("o2: "); | |
| $display(o2); | |
| $display("o3: "); | |
| $display(o3); | |
| $display("o4: "); | |
| $display(o4); | |
| s1=1'b0;s2=1'b1; | |
| #20 | |
| $display(""); | |
| $display("1"); | |
| $display(""); | |
| $display("o1: "); | |
| $display(o1); | |
| $display("o2: "); | |
| $display(o2); | |
| $display("o3: "); | |
| $display(o3); | |
| $display("o4: " | |
| $display(o4); | |
| s1=1'b1;s2=1'b0; | |
| #20 | |
| $display(""); | |
| $display("2"); | |
| $display(""); | |
| $display("o1: "); | |
| $display(o1); | |
| $display("o2: "); | |
| $display(o2); | |
| $display("o3: "); | |
| $display(o3); | |
| $display("o4: "); | |
| $display(o4); | |
| s1=1'b1;s2=1'b1; | |
| #20 | |
| $display(""); | |
| $display("3"); | |
| $display(""); | |
| $display("o1: "); | |
| $display(o1); | |
| $display("o2: "); | |
| $display(o2); | |
| $display("o3: "); | |
| $display(o3); | |
| $display("o4: "); | |
| $display(o4); | |
| end | |
| endmodule | |
| module fulladdr(a,b,s,c); | |
| input a,b; | |
| output s,c; | |
| xor x1(s,a,b); | |
| and a1(c,a,b); | |
| endmodule | |
| module demux1_4(selection_one, selection_two, data_line, op1, op2, op3, op4); | |
| input selection_one, selection_two, data_line; | |
| output op1, op2, op3, op4; | |
| //op1 = 1'b0; | |
| //op2 = 1'b0; | |
| //op3 = 1'b0; | |
| //op4 = 1'b0; | |
| case({selection_one, selection_two}) | |
| 2'b00 : assign op1 = data_line | |
| 2'b01 : assign op2 = data_line | |
| 2'b10 : assign op3 = data_line | |
| 2'b11 : assign op4 = data_line | |
| default : ; | |
| endcase | |
| endmodule |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module main; | |
| initial | |
| begin | |
| $display("Hello, World"); | |
| $finish ; | |
| end | |
| endmodule |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment