Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VeriLog 14.23 KB | None | 0 0
  1. `timescale 1ns/1ps
  2.  
  3. module AM(A, B, Sel, Out, Ovf);
  4. input [3:0] A;
  5. input [3:0] B;
  6. input [3:0] Sel;
  7. output reg [15:0] Out;
  8. output reg Ovf;
  9. wire [15:0] myout[15:0];
  10. wire myovf[15:0];
  11. priority m1(A, B, myout[0],myovf[0]);
  12. myand m2(A,B,myout[1],myovf[1]);
  13. myxor m3(A,B,myout[2],myovf[2]);
  14. mymult m4(A,B,myout[3],myovf[3]);
  15. ashiftr m5(A,B,myout[4],myovf[4]);
  16. ashiftl m6(A,B,myout[5],myovf[5]);
  17. lshiftr m7(A,B,myout[6],myovf[6]);
  18. lshiftl m8(A,B,myout[7],myovf[7]);
  19. twotofour m9(A,B,myout[8],myovf[8]);
  20. fourtosixteen m10(A,B,myout[9],myovf[9]);
  21. selectlarge m11(A,B,myout[10],myovf[10]);
  22. selectsmall m12(A,B,myout[11],myovf[11]);
  23. fulladder m13(A,B,myout[12],myovf[12]);
  24. minus m14(A,B,myout[13],myovf[13]);
  25. absolute m15(A,B,myout[14],myovf[14]);
  26. bonus a1(A,B,myout[15],myovf[15]);
  27. always@(*) begin
  28.     case(Sel)
  29.         0:begin
  30.             Out=myout[0];
  31.             Ovf=myovf[0];
  32.         end            
  33.         1:begin
  34.             Out=myout[1];
  35.             Ovf=myovf[1];
  36.         end
  37.        
  38.         2:begin
  39.             Out=myout[2];
  40.             Ovf=myovf[2];
  41.         end
  42.        
  43.         3:begin
  44.             Out=myout[3];
  45.             Ovf=myovf[3];
  46.         end
  47.        
  48.         4:begin
  49.             Out=myout[4];
  50.             Ovf=myovf[4];
  51.         end
  52.        
  53.         5:begin
  54.             Out=myout[5];
  55.             Ovf=myovf[5];
  56.         end
  57.        
  58.         6:begin
  59.             Out=myout[6];
  60.             Ovf=myovf[6];
  61.         end
  62.        
  63.         7:begin
  64.             Out=myout[7];
  65.             Ovf=myovf[7];
  66.         end
  67.        
  68.         8:begin
  69.             Out=myout[8];
  70.             Ovf=myovf[8];
  71.         end
  72.        
  73.         9:begin
  74.             Out=myout[9];
  75.             Ovf=myovf[9];
  76.         end
  77.        
  78.         10:begin
  79.             Out=myout[10];
  80.             Ovf=myovf[10];
  81.         end
  82.        
  83.         11:begin
  84.             Out=myout[11];
  85.             Ovf=myovf[11];
  86.         end
  87.        
  88.         12:begin
  89.             Out=myout[12];
  90.             Ovf=myovf[12];
  91.         end
  92.        
  93.         13:begin
  94.             Out=myout[13];
  95.             Ovf=myovf[13];
  96.         end
  97.        
  98.         14:begin
  99.             Out=myout[14];
  100.             Ovf=myovf[14];
  101.         end
  102.         15:begin
  103.             Out=myout[15];
  104.             Ovf=myovf[15];
  105.         end
  106.        
  107.  
  108.     endcase
  109. end
  110. //(your code)...
  111.  
  112. endmodule
  113.  
  114. module priority(a, b, out,ovf);
  115. input [3:0] a;
  116. input [3:0] b;
  117. output reg [15:0] out;
  118. output ovf;
  119. assign ovf=0;
  120. always@(*)begin
  121.          out[15:3]=13'b0000000000000;
  122.                 case(a)
  123.                      8,9,10,11,12,13,14,15:
  124.                         out[2:0]=3'b111;                
  125.                      4,5,6,7:
  126.                         out[2:0]=3'b110;
  127.                      2,3:
  128.                         out[2:0]=3'b101;
  129.                      1:
  130.                         out[2:0]=3'b100;
  131.                        
  132.                 default: begin
  133.                 case(b)
  134.                      8,9,10,11,12,13,14,15:
  135.                         out[2:0]=3'b011;
  136.                      4,5,6,7:
  137.                         out[2:0]=3'b010;
  138.                      2,3:
  139.                         out[2:0]=3'b001;
  140.                      1:
  141.                         out[2:0]=3'b000;
  142.                     default:begin
  143.                     end
  144.                 endcase
  145.                 end
  146.                 endcase
  147.             end
  148. endmodule
  149.  
  150. module myand(a,b,out,ovf);
  151. input [3:0] a;
  152. input [3:0] b;
  153. output [15:0] out;
  154. output ovf;
  155. assign ovf=0;
  156.     assign out[15:4]=12'b000000000000;
  157.     and a1(out[3],a[3],b[3]);
  158.     and a2(out[2],a[2],b[2]);
  159.     and a3(out[1],a[1],b[1]);
  160.     and a4(out[0],a[0],b[0]);
  161. endmodule
  162.  
  163. module myxor(a,b,out,ovf);
  164. input [3:0] a;
  165. input [3:0] b;
  166. output [15:0] out;
  167. output ovf;
  168. assign ovf=0;
  169.     assign out[15:4]=12'b000000000000;
  170.     xor a1(out[3],a[3],b[3]);
  171.     xor a2(out[2],a[2],b[2]);
  172.     xor a3(out[1],a[1],b[1]);
  173.     xor a4(out[0],a[0],b[0]);
  174.  
  175. endmodule
  176.  
  177. module mymult(a,b,out,ovf);
  178.     input signed [3:0] a;
  179.     input signed [3:0] b;
  180.     output signed [15:0] out;
  181.     assign out=a*b;
  182.     output ovf;
  183.     assign ovf=0;
  184. endmodule
  185.  
  186. module ashiftr(a,b,out,ovf);
  187.     input signed [3:0] a;
  188.     input signed [3:0] b;
  189.     output signed [15:0] out;
  190.     output ovf;
  191.     assign ovf=0;
  192.     assign out[15:4]=12'b000000000000;
  193.     assign out[3]=a[3];
  194.     assign out[2]=a[3];
  195.     assign out[1]=a[2];
  196.     assign out[0]=a[1];
  197. endmodule
  198.  
  199. module ashiftl(a,b,out,ovf);
  200.     input signed [3:0] a;
  201.     input signed [3:0] b;
  202.     output signed [15:0] out;
  203.     output ovf;
  204.     assign ovf=0;
  205.     assign out[15:4]=12'b000000000000;
  206.     assign out[3]=a[2];
  207.     assign out[2]=a[1];
  208.     assign out[1]=a[0];
  209.     assign out[0]=0;
  210. endmodule
  211.  
  212. module lshiftr(a,b,out,ovf);
  213.     input signed [3:0] a;
  214.     input signed [3:0] b;
  215.     output signed [15:0] out;
  216.     output ovf;
  217.     assign ovf=0;
  218.     assign out[15:4]=12'b000000000000;
  219.     assign out[3]=0;
  220.     assign out[2]=a[3];
  221.     assign out[1]=a[2];
  222.     assign out[0]=a[1];
  223. endmodule
  224.  
  225. module lshiftl(a,b,out,ovf);
  226.     input signed [3:0] a;
  227.     input signed [3:0] b;
  228.     output signed [15:0] out;
  229.     output ovf;
  230.     assign ovf=0;
  231.     assign out[15:4]=12'b000000000000;
  232.     assign out[3]=a[2];
  233.     assign out[2]=a[1];
  234.     assign out[1]=a[0];
  235.     assign out[0]=0;
  236. endmodule
  237.  
  238. module twotofour(a,b,out,ovf);
  239.     input  [3:0] a;
  240.     input  [3:0] b;
  241.     output  [15:0] out;
  242.     output ovf;
  243.     wire nota,notb;
  244.     buf b1(out[15],1'b0);
  245.     buf b2(out[14],1'b0);
  246.     buf b3(out[13],1'b0);
  247.     buf b4(out[12],1'b0);
  248.     buf b5(out[11],1'b0);
  249.     buf b6(out[10],1'b0);
  250.     buf b7(out[9],1'b0);
  251.     buf b8(out[8],1'b0);
  252.     buf b9(out[7],1'b0);
  253.     buf b10(out[6],1'b0);
  254.     buf b11(out[5],1'b0);
  255.     buf b12(out[4],1'b0);
  256.     buf b13(ovf,1'b0);
  257.     not sadf(nota,a[3]);
  258.     not dkek(notb,b[3]);
  259.     and a1(out[3],a[3],b[3]);
  260.     and a2(out[2],a[3],notb);
  261.     and a3(out[1],nota,b[3]);
  262.     and a4(out[0],notb,nota);
  263.    
  264. endmodule
  265.  
  266. module fourtosixteen(a,b,out,ovf);
  267.     input  [3:0] a;
  268.     input  [3:0] b;
  269.     output  [15:0] out;
  270.     output ovf;
  271.     wire [15:0] temp1;
  272.     wire [15:0] temp2;
  273.     twotofour f1({a[3],3'b000},{a[2],3'b000},temp1,ovf);
  274.     twotofour f2({b[3],3'b000},{b[2],3'b000},temp2,ovf);
  275.     and a1(out[0],temp1[0],temp2[0]);
  276.     and a2(out[1],temp1[0],temp2[1]);
  277.     and a3(out[2],temp1[0],temp2[2]);
  278.     and a4(out[3],temp1[0],temp2[3]);
  279.     and a5(out[4],temp1[1],temp2[0]);
  280.     and a6(out[5],temp1[1],temp2[1]);
  281.     and a7(out[6],temp1[1],temp2[2]);
  282.     and a8(out[7],temp1[1],temp2[3]);
  283.     and a9(out[8],temp1[2],temp2[0]);
  284.     and a10(out[9],temp1[2],temp2[1]);
  285.     and a11(out[10],temp1[2],temp2[2]);
  286.     and a12(out[11],temp1[2],temp2[3]);
  287.     and a13(out[12],temp1[3],temp2[0]);
  288.     and a14(out[13],temp1[3],temp2[1]);
  289.     and a15(out[14],temp1[3],temp2[2]);
  290.     and a16(out[15],temp1[3],temp2[3]);
  291.  
  292. endmodule
  293.  
  294. module bitslice(a,b,c,d,out);
  295.     input  a;
  296.     input  b;
  297.     input c;
  298.     input d;
  299.     output [1:0]out;
  300.     wire nota,notb,notc,notd;
  301.     wire temp1,temp2,temp3,temp4;
  302.     not n1(nota,a);
  303.     not n2(notb,b);
  304.     not n3(notc,c);
  305.     not n4(notd,d);
  306.    
  307.     and a1(temp1,c,notd);
  308.     and a2(temp2,a,notb,notd);
  309.     and a3(temp3,notc,d);
  310.     and a4(temp4,nota,b,notc);
  311.    
  312.     or o1(out[1],temp1,temp2);
  313.     or o2(out[0],temp3,temp4);
  314.    
  315.    
  316. endmodule
  317.  
  318. module selectlarge(a,b,out,ovf);
  319.     input  [3:0] a;
  320.     input  [3:0] b;
  321.     output reg [15:0] out;
  322.     output ovf;
  323.     assign ovf=1'b0;
  324.     wire [1:0] p1,p2,p3,p4;
  325.     bitslice b1(a[3],b[3],1'b0,1'b0,p1);
  326.     bitslice b2(a[2],b[2],p1[1],p1[0],p2);
  327.     bitslice b3(a[1],b[1],p2[1],p2[0],p3);
  328.     bitslice b4(a[0],b[0],p3[1],p3[0],p4);
  329.     always@(*)begin
  330.     out[15:4]=12'b000000000000;
  331.         case(p4[1])
  332.             1'b1:begin
  333.                 out[3]=a[3];
  334.                 out[2]=a[2];
  335.                 out[1]=a[1];
  336.                 out[0]=a[0];
  337.             end
  338.             1'b0:begin
  339.                    case(p4[0])
  340.            1'b1:begin
  341.                 out[3]=b[3];
  342.                 out[2]=b[2];
  343.                 out[1]=b[1];
  344.                 out[0]=b[0];
  345.              end
  346.            1'b0:begin
  347.                 out[3]=b[3];
  348.                 out[2]=b[2];
  349.                 out[1]=b[1];
  350.                 out[0]=b[0];
  351.            end
  352.        endcase
  353.  
  354.             end
  355.        endcase
  356.     end
  357. endmodule
  358.  
  359. module selectsmall(a,b,out,ovf);
  360.     input  [3:0] a;
  361.     input  [3:0] b;
  362.     output reg [15:0] out;
  363.     output ovf;
  364.     assign ovf=1'b0;
  365.     wire [1:0] p1,p2,p3,p4;
  366.     bitslice b1(a[3],b[3],1'b0,1'b0,p1);
  367.     bitslice b2(a[2],b[2],p1[1],p1[0],p2);
  368.     bitslice b3(a[1],b[1],p2[1],p2[0],p3);
  369.     bitslice b4(a[0],b[0],p3[1],p3[0],p4);
  370.     always@(*)begin
  371.     out[15:4]=12'b000000000000;
  372.         case(p4[1])
  373.             1'b1:begin
  374.                 out[3]=b[3];
  375.                 out[2]=b[2];
  376.                 out[1]=b[1];
  377.                 out[0]=b[0];
  378.             end
  379.             1'b0:begin
  380.                    case(p4[0])
  381.            1'b1:begin
  382.                 out[3]=a[3];
  383.                 out[2]=a[2];
  384.                 out[1]=a[1];
  385.                 out[0]=a[0];
  386.              end
  387.            1'b0:begin
  388.                 out[3]=b[3];
  389.                 out[2]=b[2];
  390.                 out[1]=b[1];
  391.                 out[0]=b[0];
  392.            end
  393.        endcase
  394.  
  395.             end
  396.        endcase
  397.     end
  398. endmodule
  399.  
  400. module myadder(a,b,c,cout,s);
  401.     input  a;
  402.     input  b;
  403.     input c;
  404.     output  cout,s;
  405.     wire t1,t2,t3;
  406.     xor x1(s,a,b,c);
  407.    
  408.     and a1(t1,a,b);
  409.     and a2(t2,b,c);
  410.     and a3(t3,a,c);
  411.    
  412.     or o1(cout,t1,t2,t3);    
  413. endmodule
  414.  
  415. module fulladder(a,b,out,ovf);
  416.     input signed [3:0] a;
  417.     input signed [3:0] b;
  418.     output signed [15:0] out;
  419.     output ovf;
  420.     wire cout1,cout2,cout3,cout4;
  421.     myadder m1(a[0],b[0],1'b0,cout1,out[0]);
  422.     myadder m2(a[1],b[1],cout1,cout2,out[1]);
  423.     myadder m3(a[2],b[2],cout2,cout3,out[2]);
  424.     myadder m4(a[3],b[3],cout3,cout4,out[3]);
  425.         buf b0(out[4],out[3]);
  426.         buf b11(out[5],out[3]);
  427.         buf b12(out[6],out[3]);
  428.         buf b2(out[7],out[3]);
  429.         buf b3(out[8],out[3]);
  430.         buf b4(out[9],out[3]);
  431.         buf b5(out[10],out[3]);
  432.         buf b13(out[11],out[3]);
  433.         buf b6(out[12],out[3]);
  434.         buf b7(out[13],out[3]);
  435.         buf b8(out[14],out[3]);
  436.         buf b9(out[15],out[3]);  
  437. //assign out[15:4] = {12{out[3]}};
  438.     xor x1(ovf,cout3,cout4);
  439. endmodule
  440.  
  441. module minus(a,b,out,ovf);
  442.     input signed [3:0] a;
  443.     input signed [3:0] b;
  444.     output signed [15:0] out;
  445.     output ovf;
  446.     wire b1,b2,b3,b0;
  447. /*    assign b1=b[1];
  448.     assign b2=b[2];
  449.     assign b3=b[3];
  450.     assign b4=b[0];*/
  451.     xor x2(b3,b[3],1'b1);
  452.     xor x3(b2,b[2],1'b1);
  453.     xor x4(b1,b[1],1'b1);
  454.     xor x5(b0,b[0],1'b1);
  455.    
  456.     wire cout1,cout2,cout3,cout4;
  457.     myadder m1(a[0],b0,1'b1,cout1,out[0]);
  458.     myadder m2(a[1],b1,cout1,cout2,out[1]);
  459.     myadder m3(a[2],b2,cout2,cout3,out[2]);
  460.     myadder m4(a[3],b3,cout3,cout4,out[3]);  
  461.     assign out[15:4] = {12{out[3]}};
  462.     xor x1(ovf,cout3,cout4);
  463. endmodule
  464.  
  465. module absolute(a,b,out,ovf);
  466.     input [3:0] a;
  467.     input [3:0] b;
  468.     output [15:0] out;
  469.     output ovf;
  470.     wire b1,b2,b3,b0;
  471.     xor x2(b3,b[3],1'b1);
  472.     xor x3(b2,b[2],1'b1);
  473.     xor x4(b1,b[1],1'b1);
  474.     xor x5(b0,b[0],1'b1);
  475.     wire out1,out2,out3,out0;
  476.     wire cout1,cout2,cout3,cout4;
  477.     myadder m1(a[0],b0,1'b1,cout1,out0);
  478.     myadder m2(a[1],b1,cout1,cout2,out1);
  479.     myadder m3(a[2],b2,cout2,cout3,out2);
  480.     myadder m4(a[3],b3,cout3,cout4,out3);
  481.     wire ovf1,ovf2;  
  482.     xor x1(ovf1,cout3,cout4);
  483.     wire [3:0] temp;
  484.     xor x6(temp[0],out0,out3);
  485.     xor x7(temp[1],out1,out3);
  486.     xor x8(temp[2],out2,out3);
  487.     xor x9(temp[3],out3,out3);
  488.     fulladder f1(temp,{3'b000, out3},out,ovf2);
  489.     assign out[15:4] = {12{out[3]}};
  490.     or o10(ovf,ovf1,ovf2);
  491. endmodule
  492.  
  493. module bonus(a,b,out,ovf);
  494.     input [3:0] a;
  495.     input [3:0] b;
  496.     output [15:0] out;
  497.     output ovf;
  498.     assign ovf=1'b0;    
  499.     wire temp[17:0];
  500.     wire cout[15:0];
  501.     wire s[15:0];
  502.     and a1(out[0],a[0],b[0]);
  503.     and a2(temp[0],a[1],b[0]);
  504.     and a3(temp[1],a[2],b[0]);
  505.     and a4(temp[2],a[3],b[0]);
  506.     and a5(temp[3],a[0],b[1]);
  507.     and a6(temp[4],a[1],b[1]);
  508.     and a7(temp[5],a[2],b[1]);
  509.     and a8(temp[6],a[3],b[1]);
  510.     and a9(temp[7],a[0],b[2]);
  511.     and a10(temp[8],a[1],b[2]);
  512.     and a11(temp[9],a[2],b[2]);
  513.     and a12(temp[10],a[3],b[2]);
  514.     and a13(temp[11],a[0],b[3]);
  515.     and a14(temp[12],a[1],b[3]);
  516.     and a15(temp[13],a[2],b[3]);
  517.     and a16(temp[14],a[3],b[3]);
  518.     wire [3:0] t;
  519.     wire [15:0] tt;
  520.     xor x1(t[0],temp[11],b[3]);
  521.     xor x2(t[1],temp[12],b[3]);
  522.     xor x3(t[2],temp[13],b[3]);
  523.     xor x4(t[3],temp[14],b[3]);
  524.     wire gar;
  525.     //fulladder f1(t,{3'b000, b[3]},tt,gar);
  526.     myadder m1(temp[0],temp[3],1'b0,cout[0],out[1]);
  527.     myadder m2(temp[1],temp[4],cout[0],cout[1],s[0]);
  528.     myadder m3(temp[2],temp[5],cout[1],cout[2],s[1]);
  529.     myadder m4(temp[2],temp[6],cout[2],cout[3],s[2]);
  530.     myadder m5(temp[2],temp[6],cout[3],cout[4],s[3]);
  531.     myadder m6(temp[2],temp[6],cout[4],cout[5],s[4]);
  532.      
  533.     myadder m7(s[0],temp[7],1'b0,cout[6],out[2]);
  534.     myadder m8(s[1],temp[8],cout[6],cout[7],s[5]);
  535.     myadder m9(s[2],temp[9],cout[7],cout[8],s[6]);
  536.     myadder m10(s[3],temp[10],cout[8],cout[9],s[7]);
  537.     myadder m11(s[4],temp[10],cout[9],cout[10],s[8]);
  538.    
  539.     myadder m12(s[5],t[0],b[3],cout[11],out[3]);
  540.     myadder m13(s[6],t[1],cout[11],cout[12],out[4]);
  541.     myadder m14(s[7],t[2],cout[12],cout[13],out[5]);
  542.     myadder m15(s[8],t[3],cout[13],cout[14],out[6]);
  543.     wire gar1,gar2,gar3;
  544.     wire s1,s2,s3;
  545.     myadder m16(temp[2],temp[6],cout[5],gar1,s1);
  546.     myadder m17(temp[10],s1,cout[10],gar2,s2);
  547.     myadder m18(t[3],s2,cout[14],gar3,out[7]);
  548.    
  549.    
  550.     //myadder m16(cout[5],temp[10],cout[14],gar,out[7]);
  551.     //buf bbb(out[7], out[6]);
  552.    // assign out[15:8] = {8{out[7]}};
  553.      // /*
  554.         buf b2(out[8],out[7]);
  555.         buf b3(out[9],out[7]);
  556.         buf b4(out[10],out[7]);
  557.         buf b5(out[11],out[7]);
  558.         buf b6(out[12],out[7]);
  559.         buf b7(out[13],out[7]);
  560.         buf b8(out[14],out[7]);
  561.         buf b9(out[15],out[7]);
  562.         //*/
  563.    
  564.    
  565.    
  566.    
  567.    
  568. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement