2010-05-03 7 views
1

Ceci est fichier de stimulus:comment stocker les données dans la RAM en Verilog

module final_stim; 
reg [7:0] in,in_data; 
reg clk,rst_n,rd,wr,rd_data,wr_data; 
wire [7:0] out,out_wr; 
wire[7:0] d; 
integer i; 
reg kld,f; 
reg [127:0]key; 
wire [127:0] key_expand; 
wire [7:0]out_data; 
reg [7:0] k; 
//wire [7:0] k1,k2,k3,k4,k5,k6,k7,k8,k9,k10,k11,k12,k13,k14,k15,k16; 
wire [7:0] out_data1; 

**//key_expand is da output which is giving 10 streams of size 128 bits.** 
assign k1=key_expand[127:120]; 
assign k2=key_expand[119:112]; 
assign k3=key_expand[111:104]; 
assign k4=key_expand[103:96]; 
assign k5=key_expand[95:88]; 
assign k6=key_expand[87:80]; 
assign k7=key_expand[79:72]; 
assign k8=key_expand[71:64]; 
assign k9=key_expand[63:56]; 
assign k10=key_expand[55:48]; 
assign k11=key_expand[47:40]; 
assign k12=key_expand[39:32]; 
assign k13=key_expand[31:24]; 
assign k14=key_expand[23:16]; 
assign k15=key_expand[15:8]; 
assign k16=key_expand[7:0]; 

**// then the module of memory is instanciated. 
//here k1 is sent as input.but i don know how to save the other values of k. 
//i tried to use for loop but it dint help** 
memory m1(clk,rst_n,rd, wr,k1,out_data1); 
aes_sbox b(out,d); 
initial 
begin 
    clk=1'b1; 
    rst_n=1'b0; 
    #20 
    rst_n = 1; 
    wr_data=1'b1; 
    in=8'hd4; 

    #20 
    in=8'h27; 
    rd_data=1'b0; 
    wr_data=1'b1; 

    #20 
    in=8'h11; 
    rd_data=1'b0; 
    wr_data=1'b1; 

    #20 
    in=8'hae; 
    rd_data=1'b0; 
    wr_data=1'b1; 

    #20 
    in=8'he0; 
    rd_data=1'b0; 
    wr_data=1'b1; 

    #20 
    in=8'hbf; 
    rd_data=1'b0; 
    wr_data=1'b1; 

    #20 
    in=8'h98; 
    rd_data=1'b0; 
    wr_data=1'b1; 

      #20 
    in=8'hf1; 
    rd_data=1'b0; 
    wr_data=1'b1; 

    #20 
    in=8'hb8; 
    rd_data=1'b0; 
    wr_data=1'b1; 

    #20 
    in=8'hb4; 
    rd_data=1'b0; 
    wr_data=1'b1; 

    #20 
    in=8'h5d; 
    rd_data=1'b0; 
    wr_data=1'b1; 

    #20 
    in=8'he5; 
    rd_data=1'b0; 
    wr_data=1'b1; 

    #20 
    in=8'h1e; 
    rd_data=1'b0; 
    wr_data=1'b1; 

    #20 
    in=8'h41; 
    rd_data=1'b0; 
    wr_data=1'b1; 

    #20 
    in=8'h52; 
    rd_data=1'b0; 
    wr_data=1'b1; 

    #20 
    in=8'h30; 
    rd_data=1'b0; 
    wr_data=1'b1; 

    #20 
    wr_data=1'b0; 

    #380 
    rd_data=1'b1; 

    #320 
    rd_data = 1'b0; 

    /////////////// 

    #10 
    kld = 1'b1; 
    key=128'h 2b7e151628aed2a6abf7158809cf4f3c; 

    #20 
    kld = 1'b0; 
    key = 128'h 2b7e151628aed2a6abf7158809cf4f3c; 
    wr = 1'b1; 
    rd = 1'b0; 

    #10 
    wr = 1'b1; 
    rd = 1'b1; 

    #20 
    kld = 1'b0; 
    key = 128'h 2b7e151628aed2a6abf7158809cf4f3c; 

    #20 
    kld = 1'b0; 
    key = 128'h 2b7e151628aed2a6abf7158809cf4f3c; 
    wr = 1'b1; 
    rd = 1'b1; 

    #20 
    kld = 1'b0; 
    key = 128'h 2b7e151628aed2a6abf7158809cf4f3c; 
    wr = 1'b1; 
    rd = 1'b1; 

    #20 
    kld = 1'b0; 
    key = 128'h 2b7e151628aed2a6abf7158809cf4f3c; 
    wr = 1'b1; 
    rd = 1'b1; 

    #20 
    kld = 1'b0; 
    key = 128'h 2b7e151628aed2a6abf7158809cf4f3c; 
    wr = 1'b1; 
    rd = 1'b1; 

    #20 
    kld = 1'b0; 
    key = 128'h 2b7e151628aed2a6abf7158809cf4f3c; 
    wr = 1'b1; 
    rd = 1'b1; 

    #20 
    kld = 1'b0; 
    key = 128'h 2b7e151628aed2a6abf7158809cf4f3c; 
    wr = 1'b1; 
    rd = 1'b1; 

    #20 
    kld = 1'b0; 
    key = 128'h 2b7e151628aed2a6abf7158809cf4f3c; 
    wr = 1'b1; 
    rd = 1'b1; 

    #20 
    kld = 1'b0; 
    key = 128'h 2b7e151628aed2a6abf7158809cf4f3c; 
    wr = 1'b1; 
    rd = 1'b1; 

    #20 
    kld = 1'b0; 
    key = 128'h 2b7e151628aed2a6abf7158809cf4f3c; 
    wr = 1'b1; 
    rd = 1'b1; 

    #20 
    wr = 1'b0; 
    #20 
    rd = 1'b1; 
end 

always 
    #10 clk=~clk; 
[email protected](posedge clk) 
    begin 
    #10000 
    $stop; 
    end 

endmodule 

Je rencontre un flux binaire de 128 bits à chaque posedge de clk, à savoir un flux 10 de bits totaux chacun d'une longueur de 128 bits.

Je veux diviser le train de bits 128 en 8, 8 bits et avoir à les stocker dans la mémoire vive/mémoire de largeur de 8 bits.

je l'ai fait en attribuant 8, 8 bits à la taille des fils de 8 bits. De cette façon, il y a 16 fils. Et j'utilise le double port RAM. Quand j'appelle le module de la mémoire dans le stimulus, je ne sais pas comment donner l'entrée puisque j'ai 16 fils différents nommés k1 à k16.


//Key expansion module to generate 128 bit streams(key reffered to as stream) 
//This code generates 10 keys of 128 bits each at each positive edge of clock 
module key_expansion(kld,clk,key,key_expand); 
input kld,clk; 
input [127:0] key; 
wire [31:0] w0,w1,w2,w3; 
output [127:0] key_expand; 
reg [31:0] w[3:0]; 

wire [7:0] k1,k2,k3,k4,k5,k6,k7,k8,k9,k10,k11,k12,k13,k14,k15,k16; 
wire [31:0] c0,c1,c2,c3; 
wire [31:0] tmp_w; 
wire [31:0] subword; 
wire [31:0] rcon; 
assign w0 = w[0]; 
assign w1 = w[1]; 
assign w2 = w[2]; 
assign w3 = w[3]; 
always @(posedge clk) w[0] <= #1 kld ? key[127:096] : w[0]^subword^rcon; 
always @(posedge clk) w[1] <= #1 kld ? key[095:064] : w[0]^w[1]^subword^rcon; 
always @(posedge clk) w[2] <= #1 kld ? key[063:032] : w[0]^w[2]^w[1]^subword^rcon; 
always @(posedge clk) w[3] <= #1 kld ? key[031:000] : w[0]^w[3]^w[2]^w[1]^subword^rcon; 
assign tmp_w = w[3]; 
aes_sbox u0( .a(tmp_w[23:16]), .d(subword[31:24])); 
aes_sbox u1( .a(tmp_w[15:08]), .d(subword[23:16])); 
aes_sbox u2( .a(tmp_w[07:00]), .d(subword[15:08])); 
aes_sbox u3( .a(tmp_w[31:24]), .d(subword[07:00])); 
aes_rcon r0( .clk(clk), .kld(kld), .out_rcon(rcon)); 
assign key_expand={w0,w1,w2,w3}; 
endmodule 
//stimulus for key generation 
module stim_key_exp; 
reg kld ,clk; 
reg [127:0]key; 
wire [127:0] key_expand; 
key_expansion x(kld,clk,key,key_expand); 
initial 
begin 
    clk=1'b1; 
    kld = 1'b1; 
    #20 
    kld=1'b0; 
    key=128'h 2b28ab097eaef7cf15d2154f16a6883c; 
end 
always 
#5 clk=~clk; 
[email protected](posedge clk) 
    begin 
    $monitor($time," key_expand=%h\n",key_expand); 
    #110 
    $stop; 
    end 
endmodule 

Je veux diviser les clés de chaque longueur de 128 bits en morceaux 8 bits et de les stocker.

Une chose à considérer est que la nouvelle clé est générée à chaque front d'horloge.

Ce qui est requis pour stocker une clé avant la génération de la clé suivante.

+1

Veuillez cliquer sur le bouton "101010" pour mettre en forme le code et écrire en anglais correct ponctué. – Potatoswatter

+0

j'ai hve édité l'aide de post.kindly! – anum

+2

J'ai posté une réponse. S'il vous plaît veuillez mettre en majuscule la première lettre de chaque phrase, ne pas omettre les espaces entre les mots, et ne pas abréviation de quelque chose. – Potatoswatter

Répondre

0

vous avez besoin soit d'un bloc de mémoire différent, ou un multiplexeur de bus (registre à décalage) qui peut sérialiser le flux 128 dans un courant 16x 8 bits supérieur cadencé.

Ma recommandation, du point de vue de la simplicité et l'aspect pratique, serait d'utiliser un bloc de mémoire différent. En effet, un registre de 128 bits semblerait suffisant. Notez que votre test n'utilise qu'une seule clé, donc il ne vérifie pas la fonctionnalité de la mémoire quand même. Avant de tenter de réparer quelque chose, cependant, nettoyez vraiment votre code. Est-ce que ouut est vraiment un bon nom de variable?

+0

Je travaille sur l'architecture systolique octet de AES.I besoin de diviser le flux de 128 bits. Vais-je envoyer le code générant 10 flux dont j'ai besoin de stocker en format 8 bits en mémoire? – anum

+2

@anum: Je ne vois rien de 10 là-dedans. 10 n'est pas un nombre rond en binaire. Une architecture byte-systolique nécessiterait 16 flux. Avec beaucoup d'efforts, vous pourriez obtenir 8 flux de travail en utilisant une machine d'état. Mais ce ne serait pas aussi efficace. Quoi qu'il en soit, une mémoire de 8 bits ne peut être qu'un goulot d'étranglement. Vous voulez envoyer le flux 128 bits dans le processeur systolique le plus rapidement possible, sans jamais le réduire. – Potatoswatter