update program3 with new testbench spec

This commit is contained in:
Arthur Lu 2022-08-28 00:13:43 +00:00
parent e5684b4705
commit 90c683d1da
2 changed files with 10 additions and 9 deletions

View File

@ -24,11 +24,11 @@ module program3_tb () ;
// 53 characters in length
// *** No more than 24 leading space characters, including preamble. ***
// string str1 =
// string str1 = "Mr. Watson, come here. I want to see you."; // sample program 1 input
string str1 = " A joke is a very serious thing."; // sample program 1 input
// string str1 = " Knowledge comes, but wisdom lingers. "; // alternative inputs
// string str1 = " 01234546789abcdefghijklmnopqrstuvwxyz. "; // (make up your own,
// string str1 = " A joke is a very serious thing."; // as well)
string str1 = " Ajok "; //
// string str1 = " Ajok "; //
// string str1 = "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@";
// string str1 = "``@@```@@@````@@@@````@@@@@";
// string str1 = " Knowledge comes, but wisdom lingers. "; //
@ -110,7 +110,7 @@ module program3_tb () ;
// testbench will change on falling clocks to avoid race conditions at rising clocks
for (int i=0; i<64; i++) begin
msg_crypto1[i] = ((msg_padded1[i]-'h20) ^ lfsr1[i]);
msg_crypto1[i][7] = 0;//^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",
i,msg_padded1[i],lfsr1[i],msg_crypto1[i]);
//for display purposes only, add 8'h20 to avoid nonprintable characters
@ -135,7 +135,7 @@ module program3_tb () ;
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
// set flipper = 8 or higher to disable bit corruption
flipper = 8;//$random; // value between 0 and 63, inclusive
flipper = $random;//$random; // value between 0 and 63, inclusive
dut.DM.core[n+64] = msg_crypto1[n]^(1<<flipper);
if(flipper<8) flipped[n]=1;
end

View File

@ -1,5 +1,5 @@
// Program 2 register use map:
// r0 is the accumulator, r1 r2 r3 are often used to cache temp values
// r0 is the accumulator, r1 is often used to cache temp values
// r5 is the TAP LUT link register
// r6 is LFSR tap pattern
// r7 is LFSR state value
@ -50,14 +50,14 @@ tap_init: LDI #d64
lut_return: PUT r6 // tap pattern now in r6
LDW r11 // get the first preamble character
PUT r1 // put cipher text into r1
LDI #d32 // load expected space character
LDI #d0 // load expected space character
XOR r1 // get the initial state
PUT r7 // put initial state guess into r7
NXT r11 // increment read pointer
NXT r9 // decrement total encryption chars remaining
tap_loop: LDI lfsr_routine
JAL r0 // jump to lfsr routine which calculates next state in r7
LDI #d32 // load space char expected plaintext
LDI #d0 // load space char expected plaintext
XOR r7
CLB r0 // clear leading bit in the expected ciphertext
PUT r1 // store expected cipher text in r1
@ -67,6 +67,7 @@ tap_init: LDI #d64
CLB r0 // clear leading bit for r0 since we do not expect any errors for this program
XOR r1 // XOR actual from expected, result of 0 means matching
JNZ r2 // jump to outer loop (picks new tap pattern) if the actual cipher was not equal to the expected
LDI #d0 // load preamble char
NXT r11 // increment read pointer
NXT r9 // decrement total encryption chars remaining
LDI finish_preamble // load main_loop location into r0
@ -85,7 +86,7 @@ finish_preamble: LDI lfsr_routine
PUT r1 // put the plaintext in r1
LDI finish_preamble
PUT r2 // load address of finish_preamble loop into r2
LDI #d32 // get value of space
LDI #d0 // get value of space
XOR r1 // compare if r1 == 32
JEZ r2 // jump to finish preamble loop if this plaintext == space(32)
LDI correct_pre
@ -94,7 +95,7 @@ finish_preamble: LDI lfsr_routine
JEZ r2
error_pre: LDI #x80
STW r12
LDI common
LDI common_pre
JMP r0
correct_pre: CLB r1
GET r1