题解 |
`timescale 1ns/1ns module encoder_83( input [7:0] I , input EI , output wire [2:0] Y , output wire GS , output wire EO ); assign Y[2] = EI & (I[7] | I[6] | I[5] | I[4]); assign Y[1] = EI & (I[7] | I[6] | ~I[5]&~I[4]&I[3] | ~I[5]&~I[4]&I[2]); assign Y[0] = EI & (I[7] | ~I[6]&I[5] | ~I[6]&~I[4]&I[3] | ~I[6]&~I[4]&~I[2]&I[1]); assign EO = EI&~I[7]&~I[6]&~I[5]&~I[4]&~I[3]&~I[2]&~I[1]&~I[0]; assign GS = EI&(I[7] | I[6] | I[5] | I[4] | I[3] | I[2] | I[1] | I[0]); //assign GS = EI&(| I); endmodule module encoder_164( input [15:0] A , input EI , output wire [3:0] L , output wire GS , output wire EO ); wire [1:0] EO_TEMP ; wire [2:0] Y_TOP ; wire [2:0] Y_BOTTOM ; wire [1:0] GS_TEMP ; reg [3:0] Y_TEMP ; //reg choose ; encoder_83 u_top( .I(A[15:8]), .EI(EI), .Y(Y_TOP), .GS(GS_TEMP[1]), .EO(EO_TEMP[1]) ); encoder_83 u_bottom( .I(A[7:0]), .EI(EO_TEMP[1]), .Y(Y_BOTTOM), .GS(GS_TEMP[0]), .EO(EO_TEMP[0]) ); always@(*)begin // choose = EO_TEMP[1] | EI ; case ({GS_TEMP[1],EO_TEMP[1]}) 2'b00:Y_TEMP = 4'b0000 ; 2'b01:Y_TEMP = {1'b0,Y_BOTTOM} ; 2'b10:Y_TEMP = {1'b1,Y_TOP} ; default: Y_TEMP = 4'b0000 ; endcase end assign L = Y_TEMP ; assign EO = EO_TEMP[1] & EO_TEMP[0] ; assign GS = EI & (GS_TEMP[1] | GS_TEMP[0]) ; endmodule
注意case等号左边的比特位描述