//Template //Copy this template and name it "hw2.v". // Problem 0: // Write down your name and your account here // Your Name : ####### // Your Account: ####### // //Problem 1:(10pts) //Look at the memory modules below and answer. //The memory units contain data and operators. // What will be printed? //Answer: //(hint: think about the example above) // //Instruction Memory Module //Look at it and give an answer for the problem 1. module instruction_memory(); reg [3:0] mem [7:0]; initial begin mem[0] = 1; //add mem[1] = 1; //add mem[2] = 2; //sub mem[3] = 4; //print(end) mem[4] = 2; mem[5] = 2; mem[6] = 2; mem[7] = 2; end endmodule //Instruction Memory Module module data_memory(); reg [7:0] mem [7:0]; initial begin mem[0] = 15; mem[1] = 12; mem[2] = 11; // mem[3] = 10; // mem[4] = 8; // mem[5] = 6; // mem[6] = 4; mem[7] = 2; end endmodule //Look at instruction_memory and data_memory, and give an answer for the problem 1. //You don't have to understand this code. //This module instruction_memory_read will read instruction from memory. module instruction_memory_read(v,ck); input ck; output [7:0] v; reg [7:0] v,local_v,index,cnt; instruction_memory i_m(); initial index = 0; always @(ck) begin v = i_m.mem[index]; index = index +1; end endmodule ////////////////////////////////////////////////////// ////// //Problem 2 Complete the module so it can perform the required functionality(65pts). module mini_processing_unit(v,ck); input ck; input [7:0] v; reg[7:0] data1,data2,result; reg[7:0] index; initial index = 0; data_memory dm(); always @(ck) begin #1; /// Write down your code here /// It should contain this code: $display("print value = %d\n",data1); /// 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 30 lines. /// There will be no penalty for a little bit longer code // as long as your program produces right answer // You may declare more variables and use them. //Hint use dm.mem[index] when you read data and write data to the data_memory. // for example // data1 = dm.mem[index]; //dm.mem[index] = result; end endmodule //End of your solution for problem 2. ////////////////////////////////////////////////////////////////////////////////// ////////////////////////////Do not modify this test_all module//////////////////////////////////////////////////// module test_all(); integer i,j; reg ck; wire [7:0] vs,vs2; initial ck = 0; initial begin for(i = 1; i<= 80; i = i+ 1) begin #10; ck = ~ck; end end instruction_memory_read i_m_r(vs,ck); mini_processing_unit m_p_u(vs,ck); endmodule // Problem 3: Convert the following numbers. (15pts) // 3.1) Decimal 6 to 8-bit Binary: (2pts) // Write your answer here; // 3.2) Decimal -6 to 8-bit Binary (2pts) // Write your answer here: // 3.3) Decimal 6.875 to Binary (as many bits as needed) (3pts) // Write your answer here: // 3.4) Decimal -6.875 to IEEE 754 Single Precision (8pts) // (Show in hexadecimal): // Write your answer here: