//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: Convert the following numbers. (15pts) // 1.1) Decimal 5 to 8-bit Binary: (2pts) // Write your answer here; // // 1.2) Decimal -5 to 8-bit Binary (2pts) // Write your answer here: // // 1.3) Decimal 5.875 to Binary (as many bits as needed) (3pts) // Write your answer here: // // 1.4) Decimal -5.875 to IEEE 754 Single Precision (8pts) // (Show in hexadecimal): // Write your answer here: // // Problem 2:(10pts) // Problem 2.1(5 pts) // Look at the instruction codes below and answer. // Assume the value at the memory location 10000 is 3. // What will be printed? //Answer: // Time Instruction // 0 LI R1,3 LOAD R2,(10000) // 1 ADD R3,R1,R2 LI R4,3 // 2 STORE R3,(10001) MULT R5,R3,R4 // 3 PRINT R5 NOP //(hint: think about the example above) // Problem 2.2 (5pts) // Convert this instruction code into the machine code // ADD R1,R2,R3 LI R4,3 // Hint: look at the table 6. and table 9. // The answer is a 32bit number. // Answer: // // Problem 3(65pts). module instruction_memory(); reg [31:0] mem [0:7]; initial begin mem[0] = 32'b00100010000000100001010000000001; mem[1] = 32'b10000110010100000010100000000011; mem[2] = 32'b00110110000000111010101011100000; mem[3] = 32'b10111010000000000000000000000000; mem[4] = 32'b00000000000000000000000000000000; mem[5] = 32'b00000000000000000000000000000000; mem[6] = 0; mem[7] = 0; end endmodule // Instruction Memory Module // Problem 3.1(5pts) // This following is part of instruction memory contents. // mem[0] = 32'b00100010000000100001010000000001; //machine code // mem[1] = 32'b10000110010100000010100000000011; // mem[2] = 32'b00110110000000111010101011100000; // mem[3] = 32'b10111010000000000000000000000000; // Convert those machine codes to the instructions(5pts) // (Hint: Look at the Table 8 and Table 9,the opposite of the problem 2.2) // Answer: // mem[0]= // mem[1]= // mem[2]= // mem[3]= module data_memory(); reg [31:0] mem [0:7]; initial begin mem[0] = 2; mem[1] = 3; mem[2] = 1; // mem[3] = 1; // mem[4] = 0; // mem[5] = 0; // mem[6] = 0; mem[7] = 0; end endmodule //Look at instruction_memory and data_memory. //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 [31:0] v; reg [31:0] v,index; instruction_memory i_m(); initial index = 0; always @(ck) begin v = i_m.mem[index]; index = index +1; end endmodule ////////////////////////////////////////////////////// ////// // Complete the module so it can perform the required functionality(60pts). // This mini_processing_unit will take instructions from the instruction memory // and process the instruction properly // and it will stop after executing PRINT instruction. // You may declare more variables and use them. module mini_processing_unit(v,ck); input ck; input [31:0] v; reg[31:0] data1,data2,result; reg[31:0] R[0:7]; //R0,R1,R2,R3,R4,R5,R6,R7 registers; reg[31:0] index; reg [3:0] i; initial index = 0; initial begin R[0] =0; R[1] =0; R[2] =0; R[3] =0; R[4] =0; R[5] =0; R[6] =0; R[7] =0; end data_memory dm(); always @(ck) begin #1; /// Write down your code here /// It should contain code to show the contents of registers(R0,¡¦R7) // For better understanding about the output format, // Read Help file which is given at the assignment section. // You may need these value // NOP 0000 // LOAD 0001 // LI 0010 // STORE 0011 // ADD 1000 // SUB 1001 // MULT 1010 // PRINT 1011 /// 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. // Use dm.mem[index] when you read data from the memory // and write data to the data memory. // For example // data1 = dm.mem[index]; // dm.mem[index] = result; end endmodule //End of your solution for the problem 3. ////////////////////////////////////////////////////////////////////////////////// ////////////////////////////Do not modify this test_all module//////////////////////////////////////////////////// module test_all(); integer i,j; reg ck; wire [31:0] vs; initial ck = 0; initial begin for(i = 1; i<= 4; 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 //###############YOU MAY CHECK HELP FILE FOR THE FORMAT OF YOUR OUTPUT #### //###############HELP FILE IS GIVEN ON THE ASSIGNMENTS ########################