2014-03-05 131 views
-1

我在AES的verilog代碼中發現了以下代碼片段。瞭解Verilog中的代碼片段

function [7:0] xtime; 
input [7:0] b; xtime={b[6:0],1'b0}^(8'h1b&{8{b[7]}}); 
endfunction 

請解釋一下這是幹什麼的。更詳細的解釋越好。

回答

1

b是8位輸入。

B [6:0],1'b0最後7位左移,並填充爲0

^XOR

8'h1b 8位十六進制1B與符號位相與。

解釋一行:如果MSB與0x1b XOR的設置,否則只是* 2

快速搜索xtime的和AES的使我這個C實現的評論:

// xtime is a macro that finds the product of {02} and the argument to 
// xtime modulo {1b} 
#define xtime(x) ((x<<1)^(((x>>7) & 1) * 0x11b)) 

看起來也許正在做同樣的事情。

+0

是的,8 {b [7]}是指MSB? – kamalbanga

+1

'b [7]'表示位7,在這種情況下是MSB。 '{8 {1'b1}}'意味着重複'1'b1' 8次。 – Morgan

+0

b [7]是最左邊的位,但是它被擴展爲每個位 - 在c宏中,這是與1或0相乘。在基礎實現中,這被實現爲擴展位與常數 – Simson

1

讓清理代碼和擊穿一些分配:

function [7:0] xtime; 
    input [7:0] b; 
    reg [7:0] temp1; 
    reg [7:0] temp2; 
    begin 
    temp1 = {b[6:0],1'b0}; 
    temp2 = (8'h1b & {8{b[7]}}); 
    xtime = temp1^temp2; 
    end 
endfunction 

功能稱爲xtime輸出可變xtime 8位寬。有8位寬輸入稱爲b。

temp1左移輸入b,用0填充LSB(最低有效位)並丟棄MSB(最高有效位)。

temp2按位AND s 8'h1B(8'b0001_1011)與輸入b的最高有效位。

b[7]選擇b的第7位。
{8{value}}是複製操作符。

{8{1'b1}} => 8'b1111_1111 
{4{2'b10}} => 8'b1010_1010 

xtime執行逐位的temp1temp2XOR

+0

謝謝。得到它了。 – kamalbanga