//Template //Copy this template and name it "hw3.v". // Problem 0: // Write down your name and your account here // Your Name : ####### // Your Account: ####### // //Problem 1:(5pts) //Look at the memory module below and answer //The memory unit contains data and operators. // What will be the equation? //Answer : //(hint: something like 1+2+3 =) // //Data Memory Module //Look at it and give an answer for the problem 1. module memory(); reg [7:0] mem [7:0]; initial begin mem[0] = 7+64; //tagged data for 7 mem[1] = 1; //operator code for + mem[2] = 4+128; //tagged data for -4 mem[3] = 2; //operator code for x mem[4] = 5+64; //tagged data for 5 mem[5] = 3; //operator code for = mem[6] = 3; mem[7] = 3; end endmodule //You don't have to change anything from this part. //This module memory_read_s will read 1 bit data from memory. module memory_read_s(v,ck); input ck; output v; reg [7:0] local_v, index; reg [3:0] cnt; memory m(); reg v; initial index = 0; initial cnt = 0; always @(ck) begin local_v = m.mem[index]; v = local_v[cnt]; cnt = cnt+1; if(cnt == 8) begin cnt = 0; index = index +1; end end endmodule // ////////////////////////////////////////////////////// //////You don¡¯t have to read code below. This is a part of the testbench. ///// Another data memory for the testbench ///// you don't have to know module memory2(); reg [7:0] mem [7:0]; initial begin mem[0] = 7+64; //tagged data for 7 mem[1] = 1; //operator code for + mem[2] = 4+128; //tagged data for -4 mem[3] = 2; //operator code for x mem[4] = 5+64; //tagged data for 5 mem[5] = 3; //operator code for = mem[6] = 3; mem[7] = 3; end endmodule //Read data from memory2 module memory_read_s2(v,ck); input ck; output v; reg [7:0] local_v, index; reg [3:0] cnt; memory2 m(); reg v; initial index = 0; initial cnt = 0; always @(ck) begin local_v = m.mem[index]; v = local_v[cnt]; cnt = cnt+1; if(cnt == 8) begin cnt = 0; index = index +1; end end endmodule // //Problem 2 Complete the module so it can perform the required functionality.(40pts) module serial_taggeddata_alu(result,v,ck); input v,ck; output result; reg[7:0] local_data1,local_data2,result,temp_result,temp_local_data; // you will save the incoming bit stream into the registers. // or you can declare more regs and save the value on them. reg[3:0] cnt; reg[2:0] operator; //add : 1 //multiply : 2 parameter op_add = 1; parameter op_mul = 2; initial temp_result = 0; initial operator = 3; // initial cnt = 0; always @(ck) #1 begin /// Write down your code here /// It should contain this code: $display("result output = %d\n",result); /// And this : #1 $stop; //Why #1 before $stop? //Answer: you give time to the simulator to do //something before it stops. /// The code length will be less than 40 lines. /// My code length is 33 lines. /// There will be no penalty for a little bit longer code /// as long as your program produces right answer end endmodule ////////////////////////////////////////////////////////////////////////////////// ////////////////////////////Do not modify this test_all module//////////////////////////////////////////////////// module test_all(); integer i,j; reg ck; wire [3:0] v1; wire vs,vs2; wire same; wire [7:0] result2,result; initial ck = 0; initial begin for(i = 1; i<= 80; i = i+ 1) begin #10; ck = ~ck; end end memory_read_s m_r_s(vs,ck); serial_taggeddata_alu s_a_a(result,vs,ck); memory_read_s2 m_r_s2(vs2,ck); serial_taggeddata_alu s_a_a_2(result2,vs2,ck); initial $monitor($time, " result = %d,result2 = %d",result,result2); endmodule //Problem 3 Complete the module so it can perform the required functionality.(30pts) module memory11(); reg [7:0] mem [7:0]; initial begin mem[0] = 15; mem[1] = 1; mem[2] = 8'b11110000; // mem[3] = 2; mem[4] = 8'b11111111; mem[5] = 8'b01111110; mem[6] = 3; mem[7] = 3; end endmodule //You don't have to change anything from this part. //This module memory_read_s1 will read 1 bit data from memory. module memory_read_s1(v,ck); input ck; output v; reg [7:0] local_v, index; reg [3:0] cnt; memory11 m(); reg v; initial index = 0; initial cnt = 0; always @(ck) begin local_v = m.mem[index]; v = local_v[cnt]; cnt = cnt+1; if(cnt == 8) begin cnt = 0; index = index +1; end end endmodule // ////////////////////////////////////////////////////// //////You don¡¯t have to read code below. This is a part of the testbench. module serial_pattern_checker(v,ck); input v,ck; reg[3:0] local_data1; // you will save the incoming bit stream into the register. // or you can declare more regs and save the value on them. initial local_data1 = 0; always @(ck) begin /// Write down your code here /// /// The code length will be less than 10 lines. /// use this command for displaying time: $display($time, "got pattern 1111\n"); /// There will be no penalty for a little bit longer code /// as long as your program produces right answer end endmodule ////////////////////////////////////////////////////////////////////////////////// ////////////////////////////Do not modify this test_all module//////////////////////////////////////////////////// module test_all2(); integer i,j; reg ck; wire [3:0] v1; wire vs,vs2; initial ck = 0; initial begin // #1000; for(i = 1; i<= 80; i = i+ 1) begin #1; ck = ~ck; end end memory_read_s1 m_r_s(vs,ck); serial_pattern_checker s_p_c(vs,ck); endmodule // Problem 4: Convert the following numbers. (15pts) // 4.1) Decimal 11 to 8-bit Binary: (2pts) // Write your answer here: // // 4.2) Decimal -11 to 8-bit Binary (2pts) // Write your answer here: // /// 4.3) Decimal 11.875 to Binary (as many bits as needed) (3pts) // Write your answer here: // // 4.4) Decimal -11.875 to IEEE 754 Single Precision (8pts) // (Show in hexadecimal): // Write your answer here: // //