//A=SW[13:7] 7bits Data B=SW[6:0] 7bits Data
//S2S1S0=SW[17:15] Output=LEDG[7:0] 8bits LED
module ALU( //適用於DE2-70 的程式
input [17:0]SW,
input [3:0] KEY,
input CLOCK_50,
output [17:0] LEDR,
output [7:0] LEDG,
output [6:0] HEX0,
output [6:0] HEX1,
output [6:0] HEX2,
output [6:0] HEX3,
output [6:0] HEX4,
output [6:0] HEX5,
output [6:0] HEX6,
output [6:0] HEX7
);
assign HEX0=7'b111_1111; //off 7-segment Display
assign HEX1=7'b111_1111;
assign HEX2=7'b111_1111;
assign HEX3=7'b111_1111;
assign HEX4=7'b111_1111;
assign HEX5=7'b111_1111;
assign HEX6=7'b111_1111;
assign HEX7=7'b111_1111;
assign LEDR[17:0]=SW[17:0];
wire [7:0]I0,I1,I2,I3,I4,I5,I6,I7;
assign I0= SW[13:7]+ SW[6:0]; //7bits Adder A + B
assign I1= SW[13:7] & SW[6:0]; //7bits AND A & B
assign I2= SW[13:7] +1 ; //7bits incment A +1
assign I3= SW[13:7] | SW[6:0]; //7bits OR A or B
assign I4= SW[13:7] -1 ; //7bits decment A -1
assign I5= SW[13:7] ^ SW[6:0]; //7bits XOR A ^ B
assign I6= ~(SW[13:7] ^ SW[6:0]); //7bits XNOR (~A ^ B)
assign I7= SW[13:7]-SW[6:0]; //7bits Substrator A - B
// main_8x1muxK(output [7:0] Y, input [2:0] S, input [7:0]I0,I1,I2,I3,I4,I5,I6,I7);
main_8x1mux U1(LEDG[7:0], SW[17:15] ,I0,I1,I2,I3,I4,I5,I6,I7);
endmodule
module main_8x1mux(
output [7:0] Y,
input [2:0] S,
input [7:0]I0,
input [7:0]I1,
input [7:0]I2,
input [7:0]I3,
input [7:0]I4,
input [7:0]I5,
input [7:0]I6,
input [7:0]I7);
assign Y = (S==3'b000) ? I0:
(S==3'b001) ? I1:
(S==3'b010) ? I2:
(S==3'b011) ? I3:
(S==3'b100) ? I4:
(S==3'b101) ? I5:
(S==3'b110) ? I6:
(S==3'b111) ? I7: 8'bxxxx_xxxx;
endmodule
沒有留言:
張貼留言