ELEC40006-P1-CW/testing/random.txt
2020-06-10 18:01:31 +01:00

45 lines
1.9 KiB
Plaintext

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)
(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)
(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)
(0x6) JC4 R6 R4 (if R4, in this case, n, is equal to 0, then jump to end, STP)
(0x7) MLA R1 R2 R3 (multiply and add, same as in the source code y=y*a+b)
(0x8) ADD R5 R5 R1 (adds y to the sum, so that sum+=y, as in the source code)
(0x9) SBO R4 R4 (decrease R4, i.e. n by one, so no infinite loops occur)
(0xA) JMP R7 (jumps back to check whether n>0 and if so, repeats again)
(0xB) STP
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;