Mem_array( 0 ) <= opCLR(R0) ; -- Basic I/O test 1 Mem_array( 1 ) <= opLDR(R1, R0, inSW) ; -- Load switches Mem_array( 2 ) <= opSTR(R1, R0, outHEX) ; -- Output Mem_array( 3 ) <= opBR(nzp, -3) ; -- Repeat Mem_array( 4 ) <= opCLR(R0) ; -- Basic I/O test 2 Mem_array( 5 ) <= opPSE(x"801") ; -- Checkpoint 1 - prepare to input Mem_array( 6 ) <= opLDR(R1, R0, inSW) ; -- Load switches Mem_array( 7 ) <= opSTR(R1, R0, outHEX) ; -- Output Mem_array( 8 ) <= opPSE(x"C02") ; -- Checkpoint 2 - read output, prepare to input Mem_array( 9 ) <= opBR(nzp, -4) ; -- Repeat Mem_array( 10 ) <= opCLR(R0) ; -- Basic I/O test 3 (Self-modifying code) Mem_array( 11 ) <= opPSE(x"801") ; -- Checkpoint 1 - prepare to input Mem_array( 12 ) <= opJSR(0) ; -- Get PC address Mem_array( 13 ) <= opLDR(R2,R7,3) ; -- Load pause instruction as data Mem_array( 14 ) <= opLDR(R1, R0, inSW) ; -- Load switches Mem_array( 15 ) <= opSTR(R1, R0, outHEX) ; -- Output Mem_array( 16 ) <= opPSE(x"C02") ; -- Checkpoint 2 - read output, prepare to input Mem_array( 17 ) <= opINC(R2) ; -- Increment checkpoint number Mem_array( 18 ) <= opSTR(R2,R7,3) ; -- Store new checkpoint instruction (self-modifying code) Mem_array( 19 ) <= opBR(nzp, -6) ; -- Repeat Mem_array( 20 ) <= opCLR(R0) ; -- XOR test Mem_array( 21 ) <= opPSE(x"801") ; -- Checkpoint 1 - prepare to input (upper) Mem_array( 22 ) <= opLDR(R3, R0, inSW) ; -- Load switches Mem_array( 23 ) <= opPSE(x"802") ; -- Checkpoint 2 - prepare to input (lower) Mem_array( 24 ) <= opLDR(R4, R0, inSW) ; -- Load switches again Mem_array( 25 ) <= opAND(R1, R3, R4) ; -- Combine bytes; R1: A Mem_array( 26 ) <= opPSE(x"803") ; -- Checkpoint 3 - prepare to input (upper) Mem_array( 27 ) <= opLDR(R3, R0, inSW) ; -- Load upper byte 2 Mem_array( 28 ) <= opPSE(x"804") ; -- Checkpoint 4 - prepare to input (lower) Mem_array( 29 ) <= opLDR(R4, R0, inSW) ; -- Load lower byte 2 Mem_array( 30 ) <= opAND(R2, R3, R4) ; -- Combine bytes; R2: B Mem_array( 31 ) <= opNOT(R3, R1) ; -- R3: A' Mem_array( 32 ) <= opAND(R3, R3, R2) ; -- R3: A'B Mem_array( 33 ) <= opNOT(R3, R3) ; -- R3: (A'B)' Mem_array( 34 ) <= opNOT(R4, R2) ; -- R4: B' Mem_array( 35 ) <= opAND(R4, R4, R1) ; -- R4: AB' Mem_array( 36 ) <= opNOT(R4, R4) ; -- R4: (AB')' Mem_array( 37 ) <= opAND(R3, R3, R4) ; -- R3: (A'B)'(AB')' Mem_array( 38 ) <= opNOT(R3, R3) ; -- R3: ((A'B)'(AB')')' Mem_array( 39 ) <= opSTR(R3, R0, outHEX) ; -- Output Mem_array( 40 ) <= opPSE(x"405") ; -- Checkpoint 5 - read output Mem_array( 41 ) <= opBR(nzp, -21) ; -- Repeat Mem_array( 42 ) <= opCLR(R0) ; -- Run once test (also for JMP) Mem_array( 43 ) <= opCLR(R1) ; -- clear R1 Mem_array( 44 ) <= opJSR(0) ; -- get jumpback address Mem_array( 45 ) <= opSTR(R1, R0, outHEX) ; -- output R1; LOOP DEST Mem_array( 46 ) <= opPSE(x"401") ; -- Checkpoint 1 - read output Mem_array( 47 ) <= opINC(R1) ; -- increment R1 Mem_array( 48 ) <= opRET ; -- repeat Mem_array( 49 ) <= opCLR(R0) ; -- Multiplier Program Mem_array( 50 ) <= opJSR(0) ; -- R7 <- PC (for loading bit test mask) Mem_array( 51 ) <= opLDR(R3, R7, 22) ; -- load mask; Mem_array( 52 ) <= opCLR(R4) ; -- clear R4 (iteration tracker), ; START Mem_array( 53 ) <= opCLR(R5) ; -- R5 (running total) Mem_array( 54 ) <= opPSE(x"801") ; -- Checkpoint 1 - prepare to input Mem_array( 55 ) <= opLDR(R1, R0, inSW) ; -- Input operand 1 Mem_array( 56 ) <= opPSE(x"802") ; -- Checkpoint 2 - prepare to input Mem_array( 57 ) <= opLDR(R2, R0, inSW) ; -- Input operand 2 Mem_array( 58 ) <= opADD(R5, R5, R5) ; -- shift running total; LOOP DEST Mem_array( 59 ) <= opAND(R7, R3, R1) ; -- apply mask Mem_array( 60 ) <= opBR(z, 1) ; -- test bit and jump over... Mem_array( 61 ) <= opADD(R5, R5, R2) ; -- ... the addition Mem_array( 62 ) <= opADDi(R4, R4, 0) ; -- test iteration == 0 (first iteration) Mem_array( 63 ) <= opBR(p,2) ; -- if not first iteration, jump over negation Mem_array( 64 ) <= opNOT(R5, R5) ; -- 2's compliment negate R5 Mem_array( 65 ) <= opINC(R5) ; -- (part of above) Mem_array( 66 ) <= opINC(R4) ; -- increment iteration Mem_array( 67 ) <= opADD(R1, R1, R1) ; -- shift operand 1 for mask comparisons Mem_array( 68 ) <= opADDi(R7, R4, -8) ; -- test for last iteration Mem_array( 69 ) <= opBR(n, -12) ; -- branch back to LOOP DEST if iteration < 7 Mem_array( 70 ) <= opSTR(R5, R0, outHEX) ; -- Output result Mem_array( 71 ) <= opPSE(x"403") ; -- Checkpoint 3 - read output Mem_array( 72 ) <= opBR(nzp, -21) ; -- loop back to start Mem_array( 73 ) <= x"0080" ; -- bit test mask Mem_array( 74 ) <= x"00ef" ; -- Data for Bubble Sort Mem_array( 75 ) <= x"001b" ; Mem_array( 76 ) <= x"0001" ; Mem_array( 77 ) <= x"008c" ; Mem_array( 78 ) <= x"00db" ; Mem_array( 79 ) <= x"00fa" ; Mem_array( 80 ) <= x"0047" ; Mem_array( 81 ) <= x"0046" ; Mem_array( 82 ) <= x"001f" ; Mem_array( 83 ) <= x"000d" ; Mem_array( 84 ) <= x"00b8" ; Mem_array( 85 ) <= x"0003" ; Mem_array( 86 ) <= x"006b" ; Mem_array( 87 ) <= x"004e" ; Mem_array( 88 ) <= x"00f8" ; Mem_array( 89 ) <= x"0007" ; Mem_array( 90 ) <= opCLR(R0) ; -- Bubblesort Program start Mem_array( 91 ) <= opJSR(0) ; Mem_array( 92 ) <= opADDi(R6, R7, -16) ; -- Store data location in R6 Mem_array( 93 ) <= opADDi(R6, R6, -2) ; -- (data location is 18 above the address from JSR) Mem_array( 94 ) <= opPSE(x"3FF") ; -- Checkpoint "-1" - select function; LOOP DEST Mem_array( 95 ) <= opLDR(R1, R0, inSW) ; Mem_array( 96 ) <= opBR(z, -3) ; -- If 0, retry Mem_array( 97 ) <= opDEC(R1) ; Mem_array( 98 ) <= opBR(np, 2) ; -- if selection wasn't 1, jump over… Mem_array( 99 ) <= opJSR(9) ; -- ...call to entry function Mem_array( 100 ) <= opBR(nzp, -7) ; Mem_array( 101 ) <= opDEC(R1) ; Mem_array( 102 ) <= opBR(np, 2) ; -- if selection wasn't 2, jump over… Mem_array( 103 ) <= opJSR(15) ; -- ...call to sort function Mem_array( 104 ) <= opBR(nzp, -11) ; Mem_array( 105 ) <= opDEC(R1) ; Mem_array( 106 ) <= opBR(np, -13) ; -- if selection wasn't 3, retry Mem_array( 107 ) <= opJSR(29) ; -- call to display function Mem_array( 108 ) <= opBR(nzp, -15) ; -- repeat menu Mem_array( 109 ) <= opCLR(R1) ; -- ENTRY FUNCTION Mem_array( 110 ) <= opSTR(R1, R0, outHEX) ; -- R5 is temporary index into data; R1 is counter; LOOP DEST Mem_array( 111 ) <= opPSE(x"C01") ; -- Checkpoint 1 - read data (index) and write new value Mem_array( 112 ) <= opLDR(R2, R0, inSW) ; Mem_array( 113 ) <= opADD(R5, R6, R1) ; -- generate pointer to data Mem_array( 114 ) <= opSTR(R2, R5, 0) ; -- store data Mem_array( 115 ) <= opINC(R1) ; -- increment counter Mem_array( 116 ) <= opADDi(R3, R1, -16) ; -- test for counter == 16 Mem_array( 117 ) <= opBR(n, -8) ; -- less than 16, repeat Mem_array( 118 ) <= opRET ; -- ENTRY FUNCTION RETURN Mem_array( 119 ) <= opADDi(R1, R0, -16) ; -- i = -16; SORT FUNCTION Mem_array( 120 ) <= opADDi(R2, R0, 1) ; -- j = 1; OUTER LOOP DEST Mem_array( 121 ) <= opADD(R3, R6, R2) ; -- generate pointer to data; INNER LOOP DEST Mem_array( 122 ) <= opLDR(R4, R3, -1) ; -- R4 = data[j-1] Mem_array( 123 ) <= opLDR(R5, R3, 0) ; -- R5 = data[j] Mem_array( 124 ) <= opNOT(R5, R5) ; Mem_array( 125 ) <= opADDi(R5, R5, 1) ; -- R5 = -data[j] Mem_array( 126 ) <= opADD(R5, R4, R5) ; -- R5 = data[j-1]-data[j] Mem_array( 127 ) <= opBR(nz, 3) ; -- if data[j-1] > data[j] Mem_array( 128 ) <= opLDR(R5, R3, 0) ; -- { R5 = data[j] Mem_array( 129 ) <= opSTR(R5, R3, -1) ; -- data[j-1] = data[j] Mem_array( 130 ) <= opSTR(R4, R3, 0) ; -- data[j] = R4 } // old data[j-1] Mem_array( 131 ) <= opINC(R2) ; Mem_array( 132 ) <= opADD(R3, R1, R2) ; -- Compare i and j Mem_array( 133 ) <= opBR(n, -13) ; -- INNER LOOP BACK Mem_array( 134 ) <= opINC(R1) ; Mem_array( 135 ) <= opBR(n, -16) ; -- OUTER LOOP BACK Mem_array( 136 ) <= opRET ; -- SORT FUNCTION RETURN Mem_array( 137 ) <= opCLR(R1) ; -- DISPLAY FUNCTION Mem_array( 138 ) <= opADD(R4, R7, R0) ; -- JSR shuffle to get PC value in R5 Mem_array( 139 ) <= opJSR(0) ; Mem_array( 140 ) <= opADD(R5, R7, R0) ; Mem_array( 141 ) <= opADD(R7, R4, R0) ; -- shuffle done Mem_array( 142 ) <= opLDR(R3, R5, 15) ; -- R3 = opPSE(x"802") Mem_array( 143 ) <= opADDi(R2, R0, 8) ; Mem_array( 144 ) <= opADD(R2, R2, R2) ; -- R2 = 16 Mem_array( 145 ) <= opADD(R4, R6, R1) ; -- generate pointer to data; LOOP DEST Mem_array( 146 ) <= opLDR(R4, R4, 0) ; -- load data Mem_array( 147 ) <= opSTR(R4, R0, outHEX) ; -- display data Mem_array( 148 ) <= opPSE(x"802") ; -- Checkpoint 2 - read data (self-modified instruction) Mem_array( 149 ) <= opADD(R3, R3, R2) ; -- modify register with code Mem_array( 150 ) <= opSTR(R3, R5, 8) ; -- store modified code Mem_array( 151 ) <= opINC(R1) ; -- increment counter Mem_array( 152 ) <= opADDi(R4, R1, -16) ; -- test for counter == 16 Mem_array( 153 ) <= opBR(n, -9) ; -- less than 16, repeat Mem_array( 154 ) <= opRET ; -- DISPLAY FUNCTION RETURN Mem_array( 155 ) <= opPSE(x"802") ; -- instruction as data