注意:wire类型的变量不可以在always里面进行阻塞赋值
自己写的代码(测试一直有问题,查阅书籍发现这个写的是普通编码器,并不是优先编码器):
assign Y[2] = EI&(I[7]|I[6]|I[5]|I[4]);
assign Y[1] = EI&(I[7]|I[6]|I[3]|I[2]);
assign Y[0] = EI&(I[7]|I[5]|I[3]|I[1]);
assign GS = EI&(I[7]|I[6]|I[5]|I[4]|I[3]|I[2]|I[1]|I[0]);
assign EO = EI&~I;
答案代码:
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]);