// A Saturation Arithmetic Adder // Keeps on incrementing an n-bit number // Does not wrap around to 0 when incrementing 2^n -1 // Instead, saturates the count to the largest value // Applications: brightening pixels (video), saturating volume control (audio) module saturation_arith(A, B, C); input [7:0] A, B; output [7:0] C; reg [7:0] C; reg [8:0] temp; always@(A or B) begin // I think this is how a hardware designer should think about the // design temp = A + B; // n-bit adder with n+1 bit output if( temp[8] == 1'b1) C = 8'b11111111; // saturate else C[7:0] = temp[7:0]; // Also possible to design like this, but will the hardware be cheaper // or more expensive that the above code? Think! Experiment, synthesize // the circuit and view synthesis report, resource utlization //if( A + B > 255 ) C = 255; //else C = A + B; end endmodule