Here are two very different sample solutions to Assignment 0: Maximum Of Two 8-Bit Unsigned Binary Integers.
I've also created a sample implementor's notes for them using the ACM formatting: Latex source and rendered PDF (what you would submit).
// 8-bit MAX module max(m, a, b); output [7:0] m; input [7:0] a, b; wire [7:0] d, w; assign d[7] = (a[7] ^ b[7]); assign d[6] = d[7] | (a[6] ^ b[6]); assign d[5] = d[6] | (a[5] ^ b[5]); assign d[4] = d[5] | (a[4] ^ b[4]); assign d[3] = d[4] | (a[3] ^ b[3]); assign d[2] = d[3] | (a[2] ^ b[2]); assign d[1] = d[2] | (a[1] ^ b[1]); assign d[0] = d[1] | (a[0] ^ b[0]); assign w[7] = a[7]; assign w[6] = (d[7] ? w[7] : a[6]); assign w[5] = (d[6] ? w[6] : a[5]); assign w[4] = (d[5] ? w[5] : a[4]); assign w[3] = (d[4] ? w[4] : a[3]); assign w[2] = (d[3] ? w[3] : a[2]); assign w[1] = (d[2] ? w[2] : a[1]); assign w[0] = (d[1] ? w[1] : a[0]); assign m[7] = (w[7] ? a[7] : b[7]); assign m[6] = (w[6] ? a[6] : b[6]); assign m[5] = (w[5] ? a[5] : b[5]); assign m[4] = (w[4] ? a[4] : b[4]); assign m[3] = (w[3] ? a[3] : b[3]); assign m[2] = (w[2] ? a[2] : b[2]); assign m[1] = (w[1] ? a[1] : b[1]); assign m[0] = (w[0] ? a[0] : b[0]); endmodule // REFerence 8-bit MAX module refmax(m, a, b); output [7:0] m; input [7:0] a, b; assign m = ((a > b) ? a : b); endmodule // TEST BENCH module testbench; reg [7:0] a, b; integer correct = 0; integer failed = 0; wire [7:0] m, mref; max uut(m, a, b); refmax oracle(mref, a, b); initial begin a=0; repeat (256) begin b=0; repeat (256) #1 begin if (m != mref) begin $display("Wrong: refmax(%d,%d)=%d, but max was %d", a, b, mref, m); failed = failed + 1; end else begin correct = correct + 1; end b = b + 1; end a = a + 1; end $display("All cases tested; %d correct, %d failed", correct, failed); $finish; end endmodule
// 1-bit WHO is MAX module whomax(max, a, b, maxsofar); output max; wire diff, newmax, notdiff, oldmax; input a, b, maxsofar; xor(diff, a, b); // a different from b? and(newmax, diff, a); // newmax? not(notdiff, diff); // maxsofar? and(oldmax, notdiff, maxsofar); or(max, newmax, oldmax); // whichever endmodule // 8-bit MAX module max(m, a, b); output [7:0] m; input [7:0] a, b; wire [7:0] w; whomax wm0(w[0], a[0], b[0], 1), wm1(w[1], a[1], b[1], w[0]), wm2(w[2], a[2], b[2], w[1]), wm3(w[3], a[3], b[3], w[2]), wm4(w[4], a[4], b[4], w[3]), wm5(w[5], a[5], b[5], w[4]), wm6(w[6], a[6], b[6], w[5]), wm7(w[7], a[7], b[7], w[6]); assign m = (w[7] ? a : b); endmodule // REFerence 8-bit MAX module refmax(m, a, b); output [7:0] m; input [7:0] a, b; assign m = ((a > b) ? a : b); endmodule // TEST BENCH module testbench; reg [7:0] a, b; integer correct = 0; integer failed = 0; wire [7:0] m, mref; max uut(m, a, b); refmax oracle(mref, a, b); initial begin a=0; repeat (256) begin b=0; repeat (256) #1 begin if (m != mref) begin $display("Wrong: refmax(%d,%d)=%d, but max was %d", a, b, mref, m); failed = failed + 1; end else begin correct = correct + 1; end b = b + 1; end a = a + 1; end $display("All cases tested; %d correct, %d failed", correct, failed); $finish; end endmodule
The C program that generated this page was written by Hank Dietz using the CGIC library to implement the CGI interface.
Advanced Computer Architecture.