module simple_processing_unit(s_float,a,b,c); //Complete the module so it can perform the required function. //You have to declare variables and their sizes //You may also code more modules if you need. //Your module should include the code to display the suggested output format. //Don't modify the test bench. input [2:0] a, b; input [1:0] c; output [5:0] s_float; reg [5:0] s_float; reg [5:0] temp_magnitude; always @(a or b or c) begin #1; case( c ) 2'b00: s_float = 6'b111111; 2'b01: temp_magnitude = a + b; //max_value will be 14(111+111 or 7+7,14 or 1110) 2'b10: temp_magnitude = a > b ? a - b : b - a; //take magnitude //max_magnitude will be 7 (0-7 or 7-0: 111) 2'b11: temp_magnitude = a * b; //max_value will be 49(111*111 or 7*7,49 or 110001) //but max value of the simple float format is //(011111)(simple float format) which is 11100(binary,11111 //can be represented: assuming truncation) ///m //28 without losing accuracy(4*7) or 31 with losing accuracy //any number bigger than 31 will be represented as the biggest number. //the numbers will be represented as 011111(simple float format) //those numbers are results of (7*7,6*7,5*7,6*6) default: $display("Error c\n");//catch errors to debug. endcase #1; // //You can code the part below differently. //By using while or for statement. //If you do so, the code will be shorter,and neater //but possibly difficult to understand. if(c) begin //exclude operator 2'b00 s_float =6'b000000; casex(temp_magnitude) 6'b1xxxxx: s_float =6'b011111;// if(temp_magnitude[5]==1) //Out of range so, Max 6'b01xxxx: begin s_float[4:2] =3'b111; s_float[1:0] =temp_magnitude[3:2]; end 6'b001xxx: begin s_float[4:2] =3'b110; s_float[1:0] =temp_magnitude[2:1]; end 6'b0001xx: begin s_float[4:2] =3'b101; s_float[1:0] =temp_magnitude[1:0]; end 6'b00001x: begin s_float[4:2] =3'b100; s_float[1:0] ={temp_magnitude[0],1'b0}; end 6'b000001: begin s_float[4:2] =3'b011; s_float[1:0] =2'b00; end 6'b000000: s_float = 6'b000000; default:begin $display("Error in temp\n");//catch error value to debug end endcase end /*Using WHILE and SHIFT CODE is NEATER and SHORTER Also need code to handle the max value. The main idea is the code below begin s_float[4:2] = 3'b101; while( !temp_magnitude[5] ) begin s_float[4:2] = s_float[4:2] - 1; temp_magnitude = temp_magnitude << 1; end temp_magnitude = temp_magnitude << 1; s_float[1:0] = temp_magnitude[5:4]; s_float[4:2] = s_float[4:2] + 3; end */ //Handling negative number case; when (a-b) is negative if(c==2'b10 && b>a) s_float[5] = 1'b1; // #1; $display("a=%b, b=%b, operator=%b, output=%b\n", a, b, c, s_float); end endmodule