archive:nmk206
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
archive:nmk206 [2025/05/22 12:04] – azman | archive:nmk206 [2025/06/18 08:23] (current) – [Lab Code (202425s2) Extra] azman | ||
---|---|---|---|
Line 49: | Line 49: | ||
* [Extra] {{ : | * [Extra] {{ : | ||
* Combinational Logic {{ : | * Combinational Logic {{ : | ||
- | * Sequential Logic {{ : | + | * Sequential Logic {{ : |
- | + | * State Machine {{ :archive:nmk206: | |
- | //**note**: these are from 202324s2 academic session. they should be very similar this semester, but some details may be added or removed. i usually post an updated version at the end of the week.// | + | * Simple Digital System {{ :archive:nmk206: |
- | + | ||
- | * Sequential Logic {{ :archive:pgt206: | + | |
- | * State Machine {{ :archive:pgt206: | + | |
- | * Simple Digital System {{ :archive:pgt206: | + | |
==== Verilog Coding Rule ==== | ==== Verilog Coding Rule ==== | ||
Line 87: | Line 83: | ||
* for my assessments, | * for my assessments, | ||
* **RULE**: All signals @wire must be declared! | * **RULE**: All signals @wire must be declared! | ||
+ | |||
+ | ==== Lab Code (202425s2) Archive ==== | ||
+ | |||
+ | Complete template for a simple 4-bit processor core (as discussed during class) available {{ : | ||
+ | |||
+ | ==== Lab Code (202425s2) Extra ==== | ||
+ | |||
+ | Here is an example code to utilize the carry/ | ||
+ | |||
+ | <file verilog alu_flag_4b.v> | ||
+ | module alu_4b (iS, | ||
+ | input[1:0] iS; | ||
+ | input[3:0] iP,iQ,iF; | ||
+ | output[3:0] oF,oY; | ||
+ | wire[3:0] oY; | ||
+ | wire iC, iB, oC,oB; | ||
+ | |||
+ | wire[3:0] tA0, tA1; | ||
+ | wire[3:0] tL0, tL1; | ||
+ | |||
+ | add_4b a_add (iC, | ||
+ | sub_4b a_sub (iB, | ||
+ | and_4b l_and (iP, | ||
+ | or_4b l_or (iP, | ||
+ | |||
+ | // separate flag bits for borrow and carry | ||
+ | assign oF = { 2'b00 , oB, oC }; | ||
+ | // should get from same bit position | ||
+ | assign iB = iF[1]; | ||
+ | assign iC = iF[0]; | ||
+ | |||
+ | dmux41 sel0 (iS, | ||
+ | |||
+ | endmodule | ||
+ | </ | ||
+ | |||
+ | <file verilog alu_flag_4b_tb.v> | ||
+ | module alu_4b_tb (); | ||
+ | reg[1:0] dS; | ||
+ | reg[3:0] dP,dQ,dF; | ||
+ | wire[3:0] mF,mY; | ||
+ | reg[3:0] cF,cY; | ||
+ | |||
+ | integer loop, ecnt; | ||
+ | |||
+ | initial begin | ||
+ | ecnt = 0; | ||
+ | // TASK: try to put dS assignment in a loop! => shorter code! | ||
+ | dS = 2'b00; // test add | ||
+ | for (loop=0; | ||
+ | {dF[0], | ||
+ | #5; | ||
+ | { cF[0],cY } = dF[0] + dP + dQ; | ||
+ | if (cY!=mY||cF[0]!==mF[0]) begin | ||
+ | ecnt = ecnt + 1; | ||
+ | $display(" | ||
+ | mF[0], | ||
+ | end | ||
+ | end | ||
+ | dS = 2'b01; // test sub | ||
+ | for (loop=0; | ||
+ | {dF[1], | ||
+ | #5; | ||
+ | { cF[1],cY } = dP - dQ - dF[1]; | ||
+ | if (cY!=mY||cF[1]!==mF[1]) begin | ||
+ | ecnt = ecnt + 1; | ||
+ | $display(" | ||
+ | mF[1], | ||
+ | end | ||
+ | end | ||
+ | dS = 2'b10; // test and | ||
+ | for (loop=0; | ||
+ | {dP,dQ} = loop; | ||
+ | #5; | ||
+ | cY = dP & dQ; | ||
+ | if (cY!=mY) begin | ||
+ | ecnt = ecnt + 1; | ||
+ | $display(" | ||
+ | end | ||
+ | end | ||
+ | dS = 2'b11; // test or | ||
+ | for (loop=0; | ||
+ | {dP,dQ} = loop; | ||
+ | #5; | ||
+ | cY = dP | dQ; | ||
+ | if (cY!=mY) begin | ||
+ | ecnt = ecnt + 1; | ||
+ | $display(" | ||
+ | end | ||
+ | end | ||
+ | if (ecnt==0) begin | ||
+ | $display(" | ||
+ | end | ||
+ | else begin | ||
+ | $display(" | ||
+ | end | ||
+ | end | ||
+ | |||
+ | alu_4b dut (dS, | ||
+ | |||
+ | endmodule | ||
+ | </ | ||
==== Lab Project (202425s2) Requirements ==== | ==== Lab Project (202425s2) Requirements ==== |
archive/nmk206.1747886667.txt.gz · Last modified: by azman