module ex4_top ( input [9:0] SW, output [6:0] HEX0, output [6:0] HEX1, output [6:0] HEX2, output [6:0] HEX3 ); reg [3:0] BCD0; reg [3:0] BCD1; reg [3:0] BCD2; reg [3:0] BCD3; integer i; always @ (*) begin BCD0 = 4'd0; BCD1 = 4'd0; BCD2 = 4'd0; BCD3 = 4'd0; for (i=9; i>=0; i=i-1) begin if (BCD3 >= 5) BCD3 = BCD3 +3; if (BCD2 >= 5) BCD2 = BCD2 +3; if (BCD1 >= 5) BCD1 = BCD1 +3; if (BCD0 >= 5) BCD0 = BCD0 +3; // shift each digit BCD3 = BCD3 << 1; BCD3[0] = BCD2[3]; BCD2 = BCD2 << 1; BCD2[0] = BCD1[3]; BCD1 = BCD1 << 1; BCD1[0] = BCD0[3]; BCD0 = BCD0 << 1; BCD0[0] = SW[i]; end end hex_to_7seg SEG3 (HEX3, BCD3); hex_to_7seg SEG2 (HEX2, BCD2); hex_to_7seg SEG1 (HEX1, BCD1); hex_to_7seg SEG0 (HEX0, BCD0); endmodule