//PROBLEM 2 // 1.1) Decimal 9 to 8-bit Binary: // 00001001 // // 1.2) Decimal -9 to 8-bit Binary: // 11110111 // // 1.3) Decimal 9.875 to Binary (as many bits as needed): // 1001.111 // // 1.4) Decimal -9.875 to IEEE 754 Single Precision // (Show in hexadecimal): // C11E0000 //PROBLEM 3 A) YES B) B1 NO B2 NO //PROBLEM 4 ....SOL..D.. module memory(); reg [7:0] mem [7:0]; initial begin mem[0] = 3+48; //51 ascii code for 3 mem[1] = 4+48; //52 ascii code for 4 mem[2] = 43; //43 ascii code for + mem[3] = 5+48; //53 ascii code for 5 mem[4] = 43; //43 ascii code for + mem[5] = 61; //61 ascii code for = mem[6] = 61; mem[7] = 61; end endmodule //Problem 5 Complete the module so it can perform the required functionality. // // module stack_machine(result); output result; reg[7:0] v,data1,data2,result,temp,local_data2; // you can declare more regs and wires. reg[2:0] operator;//add : 1 //subtract : 2 //no operator : 3 integer i; memory m(); parameter op_add = 1; parameter op_sub = 2; initial v = 0; initial operator = 3; always begin // Write down your code here // It should contain this code : $display("result = %d\n",result); //And this : $stop; //The code length will be less than 30 lines. //My code length is 21 lines. There will be no penalty for a little bit longer code as long as your program //produces right answer for(i = 0; i<=7;i = i+1) begin data1= m.mem[v]; data2= m.mem[v+1]; $display("datab = %b ",data1); if(data2 == 61) begin // "=" print result = data1-48; $display("result = %d\n",data1); $stop; end local_data2 = m.mem[v+2]; if(local_data2 == 43) operator = op_add;//add if(local_data2 == 45) operator = op_sub;//sub if(operator != 3) begin if(operator == op_add) temp = data1 + (data2-48);//add if(operator == op_sub) temp = data1 - (data2-48);//sub end m.mem[v+2] = temp; v = v+2; end end endmodule