2012年10月12日 星期五

P5-27 4-bit unsigned Full Adder for DE2-70 Doards


//4-bit unsigned adder





module FA4bits(SW, LEDR, LEDG);
input [17:0] SW; // toggle switches
output [17:0] LEDR; // red  LEDS   
  output [7:0] LEDG; // green LEDs
  
//set original program input , output 
wire [3:0] S;//4-bit sum
wire Cout;   //Carry out
wire [3:0] A, B; //Inputs
wire Cin;   //Carry in

   
    //mapping to hardware 
    assign LEDR = SW;
    assign A=SW[3:0];
    assign B=SW[7:4];
    assign Cin=SW[8];
    
    
    
    
    //Assign the sum of (A+B+Cin) to Cout and Sum
assign {Cout, S} = A + B + Cin;

    
    //assign output LEDG
    
    assign LEDG[4]=Cout;
    assign LEDG[3:0]=S ;
    
endmodule
    
/*    
//----------------------
//Filename : adder4.v
//----------------------                                                                                                                                                                                                                   
module adder4(S, Cout, A, B, Cin);
output [3:0] S;   //4-bit sum
output Cout;   //Carry out
input [3:0] A, B; //Inputs
input Cin;   //Carry in

//Assign the sum of (A+B+Cin) to Cout and Sum
assign {Cout, S} = A + B + Cin;

endmodule
*/

沒有留言:

張貼留言

零成本學 ESP32!在 Wokwi 打造你的第一個微型氣象站 (ESP32 + DHT22 + 1602 LCD)

零成本學 ESP32!在 Wokwi 打造你的第一個微型氣象站(溫度 濕度) (ESP32 + DHT22 + 1602 LCD) 想學物聯網(IoT)與 ESP32 電子實作,卻擔心接線與電壓規範搞砸嗎?透過強大的線上模擬器 Wokwi ,我們不需要花費任何硬體費用,打開瀏覽器...