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/06/18 08:18] – [Lab Code (202425s2) Archive] azman | archive:nmk206 [2025/07/04 10:50] (current) – [NMK206 - Computer Architecture] azman | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== NMK206 - Computer Architecture ====== | ====== NMK206 - Computer Architecture ====== | ||
| - | This course is //Computer Architecture//, | + | This course is //Computer Architecture//, |
| Download [[https:// | Download [[https:// | ||
| Line 87: | Line 87: | ||
| Complete template for a simple 4-bit processor core (as discussed during class) available {{ : | 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> | <file verilog alu_flag_4b.v> | ||
| Line 111: | Line 115: | ||
| dmux41 sel0 (iS, | 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 | endmodule | ||
archive/nmk206.1750205912.txt.gz · Last modified: by azman
