From 0e8c24217801e23f233afbd2366a4c48a7369ec1 Mon Sep 17 00:00:00 2001 From: Benjamin Ramhorst Date: Fri, 12 Jun 2020 17:52:26 +0100 Subject: [PATCH] Some testing stuff --- testing/fibonacci_alternative.cpp | 2 +- ...onacci.txt => fibonacci_not_completed.txt} | 51 +++++++++---------- .../instruction_generator.cpp | 5 +- testing/random.mif | 20 ++++++++ 4 files changed, 46 insertions(+), 32 deletions(-) rename testing/{fibonacci.txt => fibonacci_not_completed.txt} (51%) rename InstructionGenerator.cpp => testing/instruction_generator.cpp (98%) create mode 100644 testing/random.mif diff --git a/testing/fibonacci_alternative.cpp b/testing/fibonacci_alternative.cpp index 3c26971..7dd4990 100644 --- a/testing/fibonacci_alternative.cpp +++ b/testing/fibonacci_alternative.cpp @@ -4,7 +4,7 @@ using namespace std; int fib(int n){ int temp = n; //temporary variable, set equal to n - stack s; + stack s; //if n is non-negative, decrease until reaches zero to fill up stack while(temp>1){ s.push(0); //n is not 0 or 1, hence push 0 onto stack, come back later diff --git a/testing/fibonacci.txt b/testing/fibonacci_not_completed.txt similarity index 51% rename from testing/fibonacci.txt rename to testing/fibonacci_not_completed.txt index 8867dda..fd705f6 100644 --- a/testing/fibonacci.txt +++ b/testing/fibonacci_not_completed.txt @@ -1,15 +1,13 @@ Comments: - R1 holds y, as described in the source code - R2 holds a, as described in the source code - R3 holds b, as described in the source code - R4 holds n, as described in the source code - R5 holds the output (sum), as described in the source code - R6 holds the number 0xB (for jumping to the end of the program) - R7 holds the number 0x6 (for jumping back) + R1 holds n, for calculating the nth Fibonacci number + R2 holds the number 1, for comparing <=1 + R3 will hold the answers, the nth Fibonacci number (and any intermediate results) + R4 + R5 -(0x0) LDA R1 ##MEMORY_LOCATION_OF_s## (loads the seed, s, into R1, which then becomes y as in the source code) -(0x1) LDA R2 ##MEMORY_LOCATION_OF_a## (loads a into R2) -(0x2) LDA R3 ##MEMORY_LOCATION_OF_b## (loads b into R3) +(0x0) LDA R1 ##MEMORY_LOCATION_OF_n## (loads n into R1) +(0x1) LDA R2 ##MEMORY_LOCATION_CONTAINING_0x1## (loads number 1 into R2) +(0x2) LDA R3 ##MEMORY_LOCATION_OF_0x## (loads 0 into R3, we set 0 as the initial result) (0x3) LDA R4 ##MEMORY_LOCATION_OF_n## (loads n into R4) (0x4) LDA R6 ##MEMORY_LOCATION_CONTAINING_0xA## (loads 0xB, memory location of program end to R6) (0x5) LDA R7 ##MEMORY_LOCATION_CONTAINING_0x6## (loads 0x6, memory location for jumping back) @@ -21,24 +19,21 @@ Comments: (0xB) STP + +MOV + + + +JC6 ... R1 R2 +PSH R2 + + + + Example that can be used with the instruction generator program: -LDA R1 0 -LDA R2 1 -LDA R3 2 -LDA R4 3 -LDA R6 4 -LDA R7 5 -JC4 R6 R4 -MLA R1 R2 R3 -ADD R5 R5 R1 -SBO R4 R4 -JMP R7 R6 -STP + Requires setting the following data memory location: -Set location '0' to value of s; -Set location '1' to value of a; -Set location '2' to value of b; -Set location '3' to value of n; -Set location '4' to value of 0xB; -Set location '5' to value of 0x6; +Set location '0' to value of n; +Set location '1' to value of 1 (decimal number); +Set location '2' to value of 0 (decimal number) diff --git a/InstructionGenerator.cpp b/testing/instruction_generator.cpp similarity index 98% rename from InstructionGenerator.cpp rename to testing/instruction_generator.cpp index b158f3d..8c7b15a 100644 --- a/InstructionGenerator.cpp +++ b/testing/instruction_generator.cpp @@ -18,8 +18,7 @@ */ /* - IMPORTANT NOTE: For the OR instruction, enter it as "_OR", otherwise the code breaks :( - -Kacper + IMPORTANT NOTE: For the OR instruction, enter it as "_OR", otherwise the code breaks :( -Kacper */ #include @@ -72,7 +71,7 @@ string convertBinaryToHex(string binary4){ }else if(binary4=="1111"){ return "F"; }else{ - cerr << "Invalide binary quartet, cannot convert to HEX (line 78 in .cpp file)" << endl; + cerr << "Invalid binary quartet, cannot convert to HEX (line 78 in .cpp file)" << endl; assert(0); } } diff --git a/testing/random.mif b/testing/random.mif new file mode 100644 index 0000000..1867fde --- /dev/null +++ b/testing/random.mif @@ -0,0 +1,20 @@ +DEPTH = 2048; +WIDTH = 16; +ADDRESS_RADIX = DEC; +DATA_RADIX = HEX; +CONTENT +BEGIN +0 : 8800; +1 : 9001; +2 : 9802; +3 : A003; +4 : B004; +5 : B805; +6 : 0FA0; +7 : 3A53; +8 : 2969; +9 : 3520; +10 : 01C0; +11 : 7E00; +[12..2047]: 0; +END;