2015年11月25日 星期三

三位元全加法器(行為模式

module fulladder (sum, c_out, a, b, c_in);
wire s1, c1, c2;
output sum;
output c_out;
input a, b, c_in;

assign{c_out,sum}=a+b+c_in;
endmodule

module adder3(sum, c_out, a, b, c_in);
wire [2:0] c;
output [2:0] sum;
output c_out;
input [2:0] a;
input [2:0] b;
input c_in;
fulladder fa1(sum[0], c[1], a[0], b[0], c_in) ;
fulladder fa2(sum[1], c[2], a[1], b[1], c[1]) ;
fulladder fa3(sum[2], c_out, a[2], b[2], c[2]) ;


endmodule

module main;
reg [2:0] a;
reg [2:0] b;
wire [2:0] sum;
wire c_out;

adder3 DUT (sum, c_out, a, b, 1'b0);

initial
begin
  a = 4'b0101;
  b = 4'b0000;
end

always #50 begin
  b=b+1;
  $monitor("%dns monitor: a=%d b=%d sum=%d", $stime, a, b, sum);
end

initial #2000 $finish;

endmodule

三位元全加法器

module fulladder (sum, c_out, a, b, c_in);
wire s1, c1, c2;
output sum;
output c_out;
input a, b, c_in;
xor g1(s1, a, b);
xor g2(sum, s1, c_in);
and g3(c1, a,b);
and g4(c2, s1, c_in) ;
xor g5(c_out, c2, c1) ;

endmodule

module adder3(sum, c_out, a, b, c_in);
wire [2:0] c;
output [2:0] sum;
output c_out;
input [2:0] a;
input [2:0] b;
input c_in;
fulladder fa1(sum[0], c[1], a[0], b[0], c_in) ;
fulladder fa2(sum[1], c[2], a[1], b[1], c[1]) ;
fulladder fa3(sum[2], c_out, a[2], b[2], c[2]) ;


endmodule

module main;
reg [2:0] a;
reg [2:0] b;
wire [2:0] sum;
wire c_out;

adder3 DUT (sum, c_out, a, b, 1'b0);

initial
begin
  a = 4'b0101;
  b = 4'b0000;
end

always #50 begin
  b=b+1;
  $monitor("%dns monitor: a=%d b=%d sum=%d", $stime, a, b, sum);
end

initial #2000 $finish;

endmodule

2015年11月18日 星期三

F0303237

module top; 

wire A, B, Cin, c1, c2, c3, sum, Cout;
system_clock #400 clock1(Cin); 
system_clock #200 clock2(A);
system_clock #100 clock3(B);

xor(c1, A, B);
and(c2, A, B);
xor(sum, c1, Cin);
and(c3, c1, Cin);
xor(Cout, c3, Cin);

endmodule 

module system_clock(clk); 
parameter PERIOD=100; 
output clk; 
reg clk; 

initial clk=0; 

always 
 begin 
#(PERIOD/2) clk=~clk; 
 end 

always@(posedge clk)
 if($time>1000)$stop; 

endmodule 

F0303237


感謝老師指導
module test_adder1;

 reg a,b;
 reg carry_in ; 
 wire sum;
 wire carry_out;

 adder1_behavorial A1(carry_out, sum, a, b, carry_in);

 initial 
  begin

    carry_in = 0; a = 0; b = 0; 
    # 100 if ( carry_out!= 0 | sum !== 0) 
                $display(" 0+0+0=00 sum is WRONG!");
              else
                $display(" 0+0+0=00 sum is RIGHT!");
    carry_in = 0; a = 0; b = 1; 
    # 100 if ( carry_out != 0 | sum !== 1) 
               $display(" 0+0+1=01 sum is WRONG!");
              else
               $display(" 0+0+1=01 sum is RIGHT!");
    carry_in = 0; a = 1; b = 0; 
    # 100 if ( carry_out != 0 | sum !== 1) 
               $display(" 0+1+0=01 sum is WRONG!");
              else
               $display(" 0+1+0=01 sum is RIGHT!");
    carry_in = 0; a = 1; b = 1; 
    # 100 if ( carry_out != 1 | sum !== 0) 
                $display(" 0+1+1=10 sum is WRONG!");
              else
                $display(" 0+1+1=10 sum is RIGHT!");
    carry_in = 1; a = 0; b = 0; 
    # 100 if ( carry_out != 0 | sum !== 1) 
               $display(" 1+0+0=01 sum is WRONG!");
              else
               $display(" 1+0+0=01 sum is RIGHT!");
     carry_in = 1; a = 0; b = 1; 
    # 100 if ( carry_out != 1 | sum !== 0) 
                $display(" 1+0+1=10 sum is WRONG!");
              else
                $display(" 1+0+1=10 sum is RIGHT!");
    carry_in = 1; a = 1; b = 0; 
    # 100 if ( carry_out != 1 | sum !== 0) 
               $display(" 1+1+0=10 sum is WRONG!");
              else
               $display(" 1+1+0=10 sum is RIGHT!");
    carry_in = 1; a = 1; b = 1; 
    # 100 if ( carry_out!= 1 | sum !== 1) 
               $display(" 1+1+1=11 sum is WRONG!");
              else
               $display(" 1+1+1=11 sum is RIGHT!");
    $finish;
  end
endmodule



module adder1_behavorial (carry_out, sum, a, b, carry_in);
 input a, b, carry_in;
 output carry_out, sum;
  assign sum = (~a&b&~carry_in)|(~carry_in&a&~b)|(a&b&carry_in)|(~a&~b&carry_in);
  assign carry_out = a&carry_in|a&b|b&carry_in;
endmodule


2015年11月4日 星期三

123

module top;
  integer is;
  integer ia[1:0],ib[1:0];
  reg [1:0]a,b;
  reg s;
  wire [1:0]out;

  mux_behavioral mux2(out,a,b,s);

  initial
    begin
      for (is=0; is<=1; is = is + 1)
       begin
        s = is;
         for (ia[0]=0; ia[0]<=1; ia[0] = ia[0]+1)
          begin
           a[0]= ia[0];
            for (ia[1]=0; ia[1]<=1; ia[1] = ia[1]+ 1)
             begin
              a[1] = ia[1];
               for (ib[0]=0; ib[0]<=1; ib[0] = ib[0]+1)
                 begin
                   b[0] = ib[0];
                    for (ib[1]=0; ib[1]<=1; ib[1] = ib[1]+ 1)
                     begin
                      b[1] = ib[1];
                 #1 $display("a[0]=%d a[1]=%d b[0]=%d b[1]=%d s=%d out[0]%d out[1]%d",a[0],a[1],b[0],b[1],s,out[0],out[1]);
                      end
                    end
                  end
              end
         end
    end
endmodule

module mux_behavioral(OUT,A,B,SEL);
 output [1:0]OUT;
 input [1:0] A,B;
 input SEL;

mux1 X1(OUT[0],A[0],B[0],SEL);
mux1 X2(OUT[1],A[1],B[1],SEL);

endmodule

module mux1(OUT, A, B, SEL);
 output OUT;
 input A,B,SEL;

 not n1(NOT_SEL, SEL);
 and a1 (X, A, NOT_SEL);
 and a2 (Y, SEL, B);
 or  o1 (OUT, X, Y);

endmodule


F0303237薪祐

/////////////////
//行為模式
/////////////////
module top;
  integer ia,ib,is;
  reg  a,b,s;
  wire out;

  mux_behavioral mux1(out,a,b,s);

  initial
    begin
      for (is=0; is<=1; is = is+1)
        begin
          s = is;
          for (ia=0; ia<=1; ia = ia + 1)
            begin
              a = ia;
              for (ib=0; ib<=1; ib = ib + 1)
               begin
                 b = ib;
                 #1 $display("a=%d b=%d s=%d   out=%d",a,b,s,out);
               end
            end
        end
    end
endmodule

module mux_behavioral(OUT, A, B, SEL);
 output OUT;
 input A,B,SEL;
 wire  A,B,SEL;
 reg    OUT;

  always @(A or B or SEL)
   OUT = (A & SEL)|(B & ~SEL );
endmodule


2015年10月7日 星期三

感謝老師細心教導
讓我慢慢了解這些程式碼該怎麼解了

2015年9月30日 星期三

我覺得上這門課能讓我更深入了解數位邏輯的原理
也謝謝岷橋跟朱巖同學的指導
module top; 

wire A, B,C, OUT1,OUT2;
system_clock #400 clock1(A); 
system_clock #200 clock2(B);
system_clock #100 clock2(C);

and a1(OUT1, A, B);
and a1(OUT2, OUT1, C);

endmodule 

module system_clock(clk); 
parameter PERIOD=100; 
output clk; 
reg clk; 

initial clk=0; 

always 
 begin 
#(PERIOD/2) clk=~clk; 
 end 

always@(posedge clk)
 if($time>1000)$stop; 

endmodule 


2015年9月23日 星期三

薪祐

1.軟硬體系統的整合
當像是聯發科、高通、Nvidia這些晶片商在推出ARM晶片產品時,也都順帶提供了一個針對Android晶片相當完整的整合方案。而AMD雖然在行動市場上並未有所著墨,也針對了Bluestack這樣的Android虛擬平台作了投資,為的就是讓自己的產品在Windows逐漸式微的情況下可以有多一重系統程式的選擇。
而Intel雖然因為也有行動平台的方案而針對Android X86有許多修正(例如讓X86平台可運行ARM程式的patch有許多部分就來自Intel)。ˋ 但是目前卻並未正式作一個完整版本的釋出,或是讓製造商在簡易型的桌機平台使用,僅讓Android X86始終是在社群用戶流通的階段,而並未有一個成熟的版本釋出。
畢竟若是讓桌面平台在使用Android方面的使用率擴大,針對X86平台優化的軟體增多,間接地也會幫助到手機平台的部分,然而這部分是Intel應該有資源做好卻沒做的部分。
2.面對使用者的開放性
目前相當受到DIY玩家熱烈支持的Rasperry Pi,就是Intel在後PC時代要面對的第二個方面。Rasperry Pi其實就是一個ARM版的小型主機板,讓DIY玩家們可以用來開發和製作一些需要複雜控制的產品。雖然Intel有行動平台Medfield,但是幾乎都沒有可以讓DIY玩家可以如同Rasperry Pi那樣使用的產品出現。
即使是像比較精簡的Atom產品,也最多只能找到一些少數的準系統商品。或許精簡平台的DIY市場目前還並不大,但是像Rasperry Pi這樣的產品逐漸火紅而造成話題,就證明還是有部分的市場存在,而Intel在這方面卻欠缺,其實就是讓Intel商品在成為行銷話題方面的一種錯失。
3.價格
當ARM商品,可以用一個二三千塊台幣的電視棒產品,就讓電視擁有使用Android成為智慧型電視的功能。而像聯發科或是採用高通的手機,也都出現擁有雙核心以上、並運作良好的產品,而且能讓價格維持在二千元人民幣以下。即使不論ARM功耗比目前在行動產品上還是優於Intel X86 CPU的部分。

假如Intel在產品價格上還是始終沒辦法推出一個相對低廉又能為製造商們願意大量接納使用的產品的話,性能高階的商品在行動平台還不足以使用,而針對行動市場上推出的商品卻又缺乏優良的性價比,這部分就始終還是難以擴張在行動市場上的佔有率,甚至在產品的定價上,甚至出現Intel手機價格價格還比桌面電腦更貴的情形出現,這部分也讓人在價值觀上難以對於Intel行動產品能有所接受。

其實Intel Medfield產品的效能,在許多產品評測當中可以瞭解到並非遜於ARM平台。然而在上述三個方面,Intel目前的決策方向都相當封閉。許多人在手機形勢上,會拿iPhone和Android比擬為當初麥金塔和個人PC的局面。然而Intel目前的封閉形式,卻讓自己在晶片市場上的形勢更像是當初的麥金塔而非站在當初自己在個人PC上的角色。
反倒是ARM的授權模式卻讓它們在市場上的表現相當開放而被廣為接受。這部分若是Intel還是不願意改變,除了拖累了自己,也會拖累一票與之合作的電腦廠商,因為他們若是還是依附在X86 CPU的市場當中,就會持續面對到市場對於桌面CPU產品需求的疲乏而導致企業獲利面的衰退。

黃薪祐