比如5bit的結果,如果輸入高16bit全為零,則結果的最高位設置為0,否則設置為1,依次分為兩點。
-附壹個1找高位,低位也差不多。
reg [31:0]數據;
reg [ 4:0]位置;
reg[15:0]sel 1;
reg[7:0]sel 2;
reg[3:0]sel 3;
reg[2:0]sel 4;
總是@(*)開始
if(|data[31:16] == 0)開始
位置[4]= 0;
sel 1 = data[15:0];
結束
否則開始
position[4]= 1;
sel 1 = data[31:16];
結束
結束
總是@(*)開始
if(| sel 1[15:8]= = 1 ' B0)開始
位置[3]= 0;
sel 2 = sel 1[7:0];
結束
否則開始
position[3]= 1;
sel 2 = sel 1[15:8];
結束
結束
總是@(*)開始
if(|sel2[7:4] == 1'b0)開始
位置[2]= 0;
sel 3 = sel 2[3:0];
結束
否則開始
position[2]= 1;
sel 3 = sel 2[7:4];
結束
結束
總是@(*)開始
if(|sel3[3:2] == 1'b0)開始
position[1]= 0;
sel 4 = sel 3[1:0];
結束
否則開始
位置[1]= 1;
sel 4 = sel 3[3:2];
結束
結束
總是@(*)開始
if(sel4[1] == 1'b0)開始
位置[0]= 0;
結束
否則開始
position[0]= 1;
結束
結束