// Problem 0: // Write down your name and your account here // Your Name : ####### // Your Account: ####### // //Problem 1:(20pts) //Look at the memory module memory11 and answer //The memory unit contains data and operators. // 1.1.1 What will be the equation? // 1.1.2 What will be the result when you evaluate this equation by using above problem // description(not mathematical evaluation)? //Answer : //1.1.1 //1.1.2 //(hint: something like 1+2+3 =) //Data Memory Module //Look at it and give an answer for the problem 1.1.1 and 1.1.2. module memory11(); 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 //memory module for the problem 1.1.1 and 1.1.2. //Look at it and give an answer for the problem 1.2.1 and 1.2.2. //Look at the memory module memory12 and answer //The memory unit contains data and operators. // 1.2.1 What will be the equation? // 1.2.2 What will be the result when you evaluate this equation by using above problem // description(not mathematical evaluation)? //Answer : //1.2.1 //1.2.2 module memory12(); reg [7:0] mem [7:0]; initial begin mem[0] = 7+64; //tagged data for 7 mem[1] = 1; //operator code for + mem[2] = 00011100; //operator code for memory fetch(binary number) 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] = 2; //data end endmodule //memory module for the problem 1.2.1 and 1.2.2. 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. ////////////////////////////////////////////////////// //////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 module memory_address_handler(address,ck); input ck; output address; reg [2:0] address; initial address =-1; always @(posedge ck) begin address = address+1; end endmodule //Read data from memory2 module memory_read(data,address,ck); input [2:0] address; input ck; output data; reg [7:0] data; memory2 mmm(); always @(address ) begin #1; data = mmm.mem[address]; // $display("address = %d, data = %d\n",address, data); end endmodule //Problem 2-1 Modify some code to handle fetching data from memory.(10pts) //This module(data_checker) is working perfectly for the given testbench //without modifying the code because the testbench //doesn’t include fetching data from memory. module data_checker(v_alu,data,ck); input [7:0] data; input ck; output v_alu; reg [7:0] v_alu; reg [7:0] v_temp,v_temp1,v_temp2; memory2 mm(); always @(data ) begin #1; v_temp = data; v_temp1= 8'b11000011; v_temp2= v_temp1 && v_temp; /*if(v_temp2 == 0) //memory fetch begin v_temp1= 2>>v_temp1; v_temp = mm.mem[v_temp2]; end #1; //v_alu = v_temp; */ #1; v_alu =data; #1; $display("v_alu = %d\n",v_alu); end endmodule // //Problem 2-2 Complete the module so it can perform the required functionality.(40pts) module serial_taggeddata_alu(result,v_alu,ck); input [7:0] v_alu; input ck; output result; reg[7:0] local_data1,local_data2,result,temp_result,temp_local_data; // you will save the data into the registers. // or you can declare more regs and save the values on them. reg[3:0] cnt; reg[2:0] operator; //add : 1 //multiply : 2 reg[7:0] value; memory2 mm(); parameter op_add = 1; parameter op_mul = 2; initial temp_result = 0; initial operator = 3; // initial cnt = 0; always @(v_alu) #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 #1; $display("v alu at adder = %d\n",v_alu); local_data1 = v_alu; begin //fill your code here end endmodule ////////////////////////////////////////////////////////////////////////////////// ////////////////////////////Do not modify this test_all module//////////////////////////////////////////////////// module test_all(); integer i,j; reg ck; wire [3:0] v1; wire [7:0] v_alu,v_mem,vs,vs2; wire same; wire [7:0] result2,result; wire [2:0] address; initial ck = 1; // initial address =0; initial begin for(i = 1; i<= 19; i = i+ 1) begin #100; ck = ~ck; end end memory_address_handler mah(address,ck); memory_read m_r(v_mem,address,ck); data_checker d_c(v_alu,v_mem,ck); serial_taggeddata_alu s_a_a(result,v_alu,ck); //memory_read_s2 m_r_s2(vs2,ck); //serial_taggeddata_alu s_a_a_2(result2,vs2,ck); //initial // $monitor($time, " v_maddress = %d,",v_mem); endmodule // Problem 3: Convert the following numbers. (15pts) // 3.1) Decimal 11 to 8-bit Binary: (2pts) // Write your answer here: // 3.2) Decimal -11 to 8-bit Binary (2pts) // Write your answer here: // /// 3.3) Decimal 11.875 to Binary (as many bits as needed) (3pts) // Write your answer here: // // 3.4) Decimal -11.875 to IEEE 754 Single Precision (8pts) // (Show in hexadecimal): // Write your answer here: // //