Advertisement
ptrawt

CPE212-[Lab8.1] q1

Sep 6th, 2013
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module ALU1Bit(y,z,a,b,ci,c);
  2.     input a,b,ci;
  3.     input [1:0]c;
  4.     output y,z;
  5.     wire s,co;          //y0,0
  6.     wire anda;          //y0,1
  7.     wire nota;          //y1,0
  8.  
  9.     wire xorab;         //z1,1
  10.    
  11.     reg x;
  12.  
  13.     FullAdder fa1(s,co,a,b,ci); //y0,0
  14.     and and1(anda,a,b);         //y0,1
  15.     not not1(nota,a);           //y1,0
  16.  
  17.     xor xor1(xorab,a,b);        //z1,1
  18.    
  19.     Mux4to1 mux1(y,s,anda,nota,1'b0,c);
  20.     Mux4to1 mux2(z,co,x,x,xorab,c);
  21.  
  22. endmodule
  23.  
  24. module FullAdder(s,co,a,b,ci);
  25.     input a,b,ci;
  26.     output s,co;
  27.     wire xorab,andaci,andbci;
  28.    
  29.     xor xor1(xorab,a,b);
  30.     xor xor2(s,xorab,ci);
  31.  
  32.     and and1(andaci,xorab,ci);
  33.     and and2(andbci,b,a);
  34.  
  35.     or or1(co,andaci,andbci);
  36. endmodule
  37.  
  38. module Mux4to1(o,i1,i2,i3,i4,c);
  39.     input i1,i2,i3,i4;
  40.     input [1:0]c;
  41.     output o;
  42.  
  43.     wire andi1,andi2,andi3,andi4;
  44.    
  45.     input [1:0]nc;
  46.    
  47.     not not1(nc[0],c[0]);
  48.     not not2(nc[1],c[1]);
  49.  
  50.     and and1(andi1,i1,nc[1],nc[0]);
  51.     and and2(andi2,i2,nc[1],c[0]);
  52.     and and3(andi3,i3,c[1],nc[0]);
  53.     and and4(andi4,i4,c[1],c[0]);
  54.  
  55.     or or1(o,andi1,andi2,andi3,andi4);
  56. endmodule
  57.  
  58. module stimulus;
  59.     reg a,b,ci;
  60.     reg [1:0]c;
  61.     wire y,z;
  62.  
  63.     ALU1Bit alu1bit(y,z,a,b,ci,c);
  64.  
  65.     initial
  66.         begin
  67.             a = 1'b0;
  68.             b = 1'b0;
  69.             ci = 1'b0;
  70.             c = 1'b0;
  71.         end
  72.     always      #10 a = ~a;
  73.     always      #20 b = ~b;
  74.     always      #40 c[0] = ~c[0];
  75.     always      #80 c[1] = ~c[1];
  76.     always      #5  ci = ~ci;
  77.  
  78.     initial #155 $finish;
  79.  
  80.     initial
  81.         $monitor($time,"\tc = %b\ta = %d\tb = %d\tci = %d\ty = %d\tz = %d",c,a,b,ci,y,z);  
  82.    
  83. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement