fix program3_tb formatting
This commit is contained in:
parent
dd4f8ef9f8
commit
550a72588d
@ -3,29 +3,25 @@
|
|||||||
// CSE141L
|
// CSE141L
|
||||||
// runs program 2 (decrypt a message), but with corruption
|
// runs program 2 (decrypt a message), but with corruption
|
||||||
module program3_tb ();
|
module program3_tb ();
|
||||||
logic clk = 1'b0 , // advances simulation step-by-step
|
logic clk = 1'b0; // advances simulation step-by-step
|
||||||
init = 1'b1 , // init (reset) command to DUT
|
logic init = 1'b1; // init (reset) command to DUT
|
||||||
start = 1'b1 ; // req (start program) command to DUT
|
logic start = 1'b1; // req (start program) command to DUT
|
||||||
wire done; // done flag returned by DUT
|
wire done; // done flag returned by DUT
|
||||||
logic[3:0] pre_length; // space char. bytes before first char. in message
|
logic[3:0] pre_length; // space char. bytes before first char. in message
|
||||||
logic[7:0] message1[49] , // original raw message, in binary
|
logic[7:0] message1[49]; // original raw message, in binary
|
||||||
msg_padded1[80], // original message, plus pre- and post-padding w/ ASCII spaces
|
logic[7:0] msg_padded1[80]; // original message, plus pre- and post-padding w/ ASCII spaces
|
||||||
msg_crypto1[64]; // encrypted message according to the DUT
|
logic[7:0] msg_crypto1[64]; // encrypted message according to the DUT
|
||||||
logic[6:0] lfsr_ptrn , // chosen one of 9 maximal length 7-tap shift reg. ptrns
|
logic[6:0] lfsr_ptrn; // chosen one of 9 maximal length 7-tap shift reg. ptrns
|
||||||
LFSR_ptrn[9] , // the 9 candidate maximal-length 7-bit LFSR tap ptrns
|
logic[6:0] LFSR_ptrn[9]; // the 9 candidate maximal-length 7-bit LFSR tap ptrns
|
||||||
lfsr1[64] , // states of program 1 encrypting LFSR
|
logic[6:0] lfsr1[64]; // states of program 1 encrypting LFSR
|
||||||
LFSR_init ; // one of 127 possible NONZERO starting states
|
logic[6:0] LFSR_init; // one of 127 possible NONZERO starting states
|
||||||
int score; // count of correct encyrpted characters
|
int score; // count of correct encyrpted characters
|
||||||
|
|
||||||
// our original American Standard Code for Information Interchange message follows
|
// our original American Standard Code for Information Interchange message follows
|
||||||
// note in practice your design should be able to handle ANY ASCII string that is
|
// note in practice your design should be able to handle ANY ASCII string that is
|
||||||
// restricted to characters between space (0x20) and script f (0x9f) and shorter than
|
// restricted to characters between space (0x20) and script f (0x9f) and shorter than
|
||||||
// 53 characters in length
|
// 53 characters in length
|
||||||
string str1 = " four score and seven years ago..."; // sample program 1 input
|
string str1 = " four score and seven years ago...";
|
||||||
// string str1 = " Knowledge comes, but wisdom lingers. "; // alternative inputs
|
|
||||||
// string str1 = " 01234546789abcdefghijklmnopqrstuvwxyz. "; // (make up your own,
|
|
||||||
// string str1 = " f A joke is a very serious thing."; // as well)
|
|
||||||
// string str1 = " Ajok "; //
|
|
||||||
// string str1 = " Knowledge comes, but wisdom lingers. "; //
|
|
||||||
|
|
||||||
// displayed encrypted string will go here:
|
// displayed encrypted string will go here:
|
||||||
string str_enc1[64]; // program 1 desired output will go here
|
string str_enc1[64]; // program 1 desired output will go here
|
||||||
@ -35,7 +31,8 @@ module program3_tb () ;
|
|||||||
int space; // counts leading space characters in message
|
int space; // counts leading space characters in message
|
||||||
logic [5:0] flipper; // corruptor -- bit flip
|
logic [5:0] flipper; // corruptor -- bit flip
|
||||||
logic [79:0] flipped = 80'b0; // tracks which word got a bit flipped
|
logic [79:0] flipped = 80'b0; // tracks which word got a bit flipped
|
||||||
// the 8 possible maximal-length feedback tap patterns from which to choose
|
|
||||||
|
// the 9 possible maximal-length feedback tap patterns from which to choose
|
||||||
assign LFSR_ptrn[0] = 7'h60; // 110_0000
|
assign LFSR_ptrn[0] = 7'h60; // 110_0000
|
||||||
assign LFSR_ptrn[1] = 7'h48;
|
assign LFSR_ptrn[1] = 7'h48;
|
||||||
assign LFSR_ptrn[2] = 7'h78;
|
assign LFSR_ptrn[2] = 7'h78;
|
||||||
@ -74,17 +71,13 @@ module program3_tb () ;
|
|||||||
);
|
);
|
||||||
|
|
||||||
initial begin
|
initial begin
|
||||||
//***** pre-load your instruction ROM here or inside itself *****
|
|
||||||
// $readmemb("encoder.bin", dut.instr_rom.rom);
|
|
||||||
// you may also pre-load desired constants, etc. into
|
|
||||||
// your data_mem here -- the upper addresses are reserved for your use
|
|
||||||
// dut.data_mem.DM[128]=8'hfe; //whatever constants you want
|
|
||||||
file_no = 'b1; // create your output file
|
file_no = 'b1; // create your output file
|
||||||
#0ns strlen = str1.len; // length of string 1 (# characters between " ")
|
#0ns strlen = str1.len; // length of string 1 (# characters between " ")
|
||||||
if(strlen>52) strlen = 52; // clip message at 52 characters
|
if(strlen>52) strlen = 52; // clip message at 52 characters
|
||||||
for(space=0;space<24;space++) // count leading spaces in message
|
for(space=0;space<24;space++) // count leading spaces in message
|
||||||
if(str1[space]==8'h20) continue;
|
if(str1[space]==8'h20) continue;
|
||||||
else break;
|
else break;
|
||||||
|
|
||||||
// program 1 -- precompute encrypted message
|
// program 1 -- precompute encrypted message
|
||||||
lfsr1[0] = LFSR_init; // any nonzero value (zero may be helpful for debug)
|
lfsr1[0] = LFSR_init; // any nonzero value (zero may be helpful for debug)
|
||||||
$fdisplay(file_no,"run encryption program; original message = ");
|
$fdisplay(file_no,"run encryption program; original message = ");
|
||||||
@ -103,8 +96,7 @@ module program3_tb () ;
|
|||||||
for (int i=0; i<64; i++) begin
|
for (int i=0; i<64; i++) begin
|
||||||
msg_crypto1[i] = (msg_padded1[i] ^ lfsr1[i]);
|
msg_crypto1[i] = (msg_padded1[i] ^ lfsr1[i]);
|
||||||
msg_crypto1[i][7] = ^msg_crypto1[i][6:0]; // prepend parity bit into MSB
|
msg_crypto1[i][7] = ^msg_crypto1[i][6:0]; // prepend parity bit into MSB
|
||||||
$fdisplay(file_no,"i=%d, msg_pad=0x%h, lfsr=%b msg_crypt w/ parity = 0x%h",
|
$fdisplay(file_no,"i=%d, msg_pad=0x%h, lfsr=%b msg_crypt w/ parity = 0x%h", i,msg_padded1[i],lfsr1[i],msg_crypto1[i]);
|
||||||
i,msg_padded1[i],lfsr1[i],msg_crypto1[i]);
|
|
||||||
str_enc1[i] = string'(msg_crypto1[i][6:0]);
|
str_enc1[i] = string'(msg_crypto1[i][6:0]);
|
||||||
end
|
end
|
||||||
$fdisplay(file_no,"encrypted string = ");
|
$fdisplay(file_no,"encrypted string = ");
|
||||||
@ -115,13 +107,6 @@ module program3_tb () ;
|
|||||||
// run encryption program first to know what to decrypt
|
// run encryption program first to know what to decrypt
|
||||||
// ***** load operands into your data memory *****
|
// ***** load operands into your data memory *****
|
||||||
// ***** use your instance name for data memory and its internal core *****
|
// ***** use your instance name for data memory and its internal core *****
|
||||||
// for(int m=0; m<61; m++)
|
|
||||||
// dut.DM.core[m] = 8'h20; // pad memory w/ ASCII space characters
|
|
||||||
// for(int m=0; m<strlen; m++)
|
|
||||||
// dut.DM.core[m] = str1[m]; // overwrite/copy original string into device's data memory[0:strlen-1]
|
|
||||||
// dut.DM.core[61] = pre_length; // number of bytes preceding message
|
|
||||||
// dut.DM.core[62] = lfsr_ptrn; // LFSR feedback tap positions (9 possible ptrns)
|
|
||||||
// dut.DM.core[63] = LFSR_init; // LFSR starting state (nonzero)
|
|
||||||
for(int m=0; m<24; m++) // load first 24 characters of encrypted message into data memory
|
for(int m=0; m<24; m++) // load first 24 characters of encrypted message into data memory
|
||||||
dut.DM.core[m+64] = msg_crypto1[m];
|
dut.DM.core[m+64] = msg_crypto1[m];
|
||||||
for(int n=24; n<64; n++) begin // load subsequent, possibly corrupt, encrypted message into data memory
|
for(int n=24; n<64; n++) begin // load subsequent, possibly corrupt, encrypted message into data memory
|
||||||
@ -130,12 +115,14 @@ module program3_tb () ;
|
|||||||
dut.DM.core[n+64] = msg_crypto1[n]^(1<<flipper);
|
dut.DM.core[n+64] = msg_crypto1[n]^(1<<flipper);
|
||||||
if(flipper<8) flipped[n]=1;
|
if(flipper<8) flipped[n]=1;
|
||||||
end
|
end
|
||||||
|
|
||||||
#20ns init = 1'b0; // suggestion: reset = 1 forces your program counter to 0
|
#20ns init = 1'b0; // suggestion: reset = 1 forces your program counter to 0
|
||||||
#10ns start = 1'b0; // request/start = 1 holds your program counter
|
#10ns start = 1'b0; // request/start = 1 holds your program counter
|
||||||
#60ns; // wait for 6 clock cycles of nominal 10ns each
|
#60ns; // wait for 6 clock cycles of nominal 10ns each
|
||||||
wait(done); // wait for DUT's ack/done flag to go high
|
wait(done); // wait for DUT's ack/done flag to go high
|
||||||
#10ns $fdisplay(file_no,"");
|
#10ns $fdisplay(file_no,"");
|
||||||
$fdisplay(file_no,"program 3:");
|
$fdisplay(file_no,"program 3:");
|
||||||
|
|
||||||
// ***** reads your results and compares to test bench
|
// ***** reads your results and compares to test bench
|
||||||
// ***** use your instance name for data memory and its internal core *****
|
// ***** use your instance name for data memory and its internal core *****
|
||||||
for(int n=0; n<64; n++) begin
|
for(int n=0; n<64; n++) begin
|
||||||
@ -143,20 +130,19 @@ module program3_tb () ;
|
|||||||
if(dut.DM.core[n][7]) begin
|
if(dut.DM.core[n][7]) begin
|
||||||
$fdisplay(file_no, "error successfully flagged");
|
$fdisplay(file_no, "error successfully flagged");
|
||||||
score++;
|
score++;
|
||||||
end else begin
|
end
|
||||||
|
else begin
|
||||||
$fdisplay(file_no, "failed to flag error");
|
$fdisplay(file_no, "failed to flag error");
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else if({flipped[n+pre_length+space],msg_padded1[n+pre_length+space][6:0]}
|
else if({flipped[n+pre_length+space],msg_padded1[n+pre_length+space][6:0]} == dut.DM.core[n]) begin
|
||||||
== dut.DM.core[n]) begin
|
$fdisplay(file_no,"%d bench msg: %s %h dut msg: %h", n, msg_padded1[n+pre_length+space][6:0], msg_padded1[n+pre_length+space], dut.DM.core[n]);
|
||||||
$fdisplay(file_no,"%d bench msg: %s %h dut msg: %h",
|
|
||||||
n, msg_padded1[n+pre_length+space][6:0], msg_padded1[n+pre_length+space], dut.DM.core[n]);
|
|
||||||
score++;
|
score++;
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
$fdisplay(file_no,"%d bench msg: %s %h dut msg: %h OOPS!",
|
$fdisplay(file_no,"%d bench msg: %s %h dut msg: %h OOPS!", n, msg_padded1[n+pre_length+space][6:0], msg_padded1[n+pre_length+space], dut.DM.core[n]);
|
||||||
n, msg_padded1[n+pre_length+space][6:0], msg_padded1[n+pre_length+space], dut.DM.core[n]);
|
|
||||||
end
|
end
|
||||||
|
|
||||||
$fdisplay(file_no,"score = %d/64",score);
|
$fdisplay(file_no,"score = %d/64",score);
|
||||||
#20ns $fclose(file_no);
|
#20ns $fclose(file_no);
|
||||||
#20ns $stop;
|
#20ns $stop;
|
||||||
|
Reference in New Issue
Block a user