From 550a72588d8762bd62a3701a13944b58bc6e47b0 Mon Sep 17 00:00:00 2001 From: Arthur Lu Date: Fri, 19 Aug 2022 20:24:19 -0700 Subject: [PATCH] fix program3_tb formatting --- RTL/program3_tb.sv | 262 +++++++++++++++++++++------------------------ 1 file changed, 124 insertions(+), 138 deletions(-) diff --git a/RTL/program3_tb.sv b/RTL/program3_tb.sv index 73743a7..c829dbf 100644 --- a/RTL/program3_tb.sv +++ b/RTL/program3_tb.sv @@ -2,49 +2,46 @@ // testbench for programmable message decryption, space removal (Program #3) // CSE141L // runs program 2 (decrypt a message), but with corruption -module program3_tb () ; - logic clk = 1'b0 , // advances simulation step-by-step - init = 1'b1 , // init (reset) command to DUT - start = 1'b1 ; // req (start program) command to DUT - wire done ; // done flag returned by DUT - logic[3:0] pre_length ; // space char. bytes before first char. in message - logic[7:0] message1[49] , // original raw message, in binary - msg_padded1[80], // original message, plus pre- and post-padding w/ ASCII spaces - 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 - LFSR_ptrn[9] , // the 9 candidate maximal-length 7-bit LFSR tap ptrns - lfsr1[64] , // states of program 1 encrypting LFSR - LFSR_init ; // one of 127 possible NONZERO starting states - int score ; // count of correct encyrpted characters -// 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 -// restricted to characters between space (0x20) and script f (0x9f) and shorter than -// 53 characters in length - string str1 = " four score and seven years ago..."; // sample program 1 input -// 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. "; // +module program3_tb (); + logic clk = 1'b0; // advances simulation step-by-step + logic init = 1'b1; // init (reset) command to DUT + logic start = 1'b1; // req (start program) command to DUT + wire done; // done flag returned by DUT + 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] msg_padded1[80]; // original message, plus pre- and post-padding w/ ASCII spaces + 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[9]; // the 9 candidate maximal-length 7-bit LFSR tap ptrns + logic[6:0] lfsr1[64]; // states of program 1 encrypting LFSR + logic[6:0] LFSR_init; // one of 127 possible NONZERO starting states + int score; // count of correct encyrpted characters -// displayed encrypted string will go here: - string str_enc1[64]; // program 1 desired output will go here - int strlen; // incoming string length - int pt_no; // select LFSR pattern, value 0 through 8 - int file_no; // write to file - int space; // counts leading space characters in message - logic[5:0] flipper; // corruptor -- bit flip - 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 - assign LFSR_ptrn[0] = 7'h60; // 110_0000 - assign LFSR_ptrn[1] = 7'h48; - assign LFSR_ptrn[2] = 7'h78; - assign LFSR_ptrn[3] = 7'h72; - assign LFSR_ptrn[4] = 7'h6A; - assign LFSR_ptrn[5] = 7'h69; - assign LFSR_ptrn[6] = 7'h5C; - assign LFSR_ptrn[7] = 7'h7E; - assign LFSR_ptrn[8] = 7'h7B; + // 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 + // restricted to characters between space (0x20) and script f (0x9f) and shorter than + // 53 characters in length + string str1 = " four score and seven years ago..."; + + // displayed encrypted string will go here: + string str_enc1[64]; // program 1 desired output will go here + int strlen; // incoming string length + int pt_no; // select LFSR pattern, value 0 through 8 + int file_no; // write to file + int space; // counts leading space characters in message + logic [5:0] flipper; // corruptor -- bit flip + logic [79:0] flipped = 80'b0; // tracks which word got a bit flipped + + // the 9 possible maximal-length feedback tap patterns from which to choose + assign LFSR_ptrn[0] = 7'h60; // 110_0000 + assign LFSR_ptrn[1] = 7'h48; + assign LFSR_ptrn[2] = 7'h78; + assign LFSR_ptrn[3] = 7'h72; + assign LFSR_ptrn[4] = 7'h6A; + assign LFSR_ptrn[5] = 7'h69; + assign LFSR_ptrn[6] = 7'h5C; + assign LFSR_ptrn[7] = 7'h7E; + assign LFSR_ptrn[8] = 7'h7B; always_comb begin pt_no = $urandom_range(0, 8); @@ -65,106 +62,95 @@ module program3_tb () ; else if(pre_length > 26) pre_length = 26; // prevets pre_length > 26 end -// ***** instantiate your own top level design here ***** - top_level dut( - .clk (clk ), // input: use your own port names, if different - .init (init ), // input: some prefer to call this ".reset" - .req (start), // input: launch program - .ack (done ) // output: "program run complete" - ); + // ***** instantiate your own top level design here ***** + top_level dut( + .clk(clk), // input: use your own port names, if different + .init(init), // input: some prefer to call this ".reset" + .req(start), // input: launch program + .ack(done) // output: "program run complete" + ); - 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 - #0ns strlen = str1.len; // length of string 1 (# characters between " ") - if(strlen>52) strlen = 52; // clip message at 52 characters - for(space=0;space<24;space++) // count leading spaces in message - if(str1[space]==8'h20) continue; - else break; -// program 1 -- precompute encrypted message - lfsr1[0] = LFSR_init; // any nonzero value (zero may be helpful for debug) - $fdisplay(file_no,"run encryption program; original message = "); - $fdisplay(file_no,"%s",str1); // print original message in transcript window - $fdisplay(file_no,"LFSR_ptrn = 0x%h, LFSR_init = 0x%h, pre_length: %d",lfsr_ptrn,LFSR_init,pre_length); - for(int j=0; j<80; j++) // pre-fill message_padded with ASCII space characters - msg_padded1[j] = 8'h20; // - for(int l=0; l