module mult8x8(y,a,b,clock); input [8:0] a,b; output [16:0] y; input clock; reg [8:0] sum,dif,alb,bla; reg sign0; always @(posedge clock) begin : stage0 sum <= a[7:0] + b[7:0]; // add the magnitudes // have to deal with underfow in the difference alb = a[7:0] - b[7:0]; bla = b[7:0] - a[7:0]; if (alb[8]) dif <= bla; else dif <= alb; // compute sign sign0 <= a[8] ^ b[8]; end reg [17:0] sum_squared, dif_squared; reg sign1; always @(posedge clock) begin : stage1 sign1 <= sign0; sum_squared <= sum*sum; dif_squared <= dif*dif; end reg [17:0] magnitude; reg [16:0] y; always @(posedge clock) begin : stage2 magnitude = sum_squared - dif_squared; y <= magnitude >> 2; y[16] <= sign1; end endmodule