31 lines
1.5 KiB
Plaintext
31 lines
1.5 KiB
Plaintext
program Crazy 8
|
|
// Input: A list of up to 16 positive integers terminated by a 0000
|
|
// Output: The positive integers in reverse order
|
|
// Remarks: The data is stored starting at memory location 00.
|
|
// If you enter more than 16 integers, you will overwrite
|
|
// the program itself. To see the crazy 8 virus, enter
|
|
// 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 (16 1's)
|
|
// 8888 8810 98FF C011
|
|
// -----------------------------------------------------------------------------
|
|
10: 7101 R[1] <- 0001 R[1] always 1
|
|
11: 7A00 R[A] <- 0000 memory address of array a[]
|
|
12: 7B00 R[B] <- 0000 # elements in array = n
|
|
|
|
// Read in sequence of positive integers
|
|
13: 8CFF read R[C] while (1) {
|
|
14: CC19 if (R[C] == 0) goto 19 if ((read R[C]) == 0) break
|
|
15: 16AB R[6] <- R[A] + R[B] a + n
|
|
16: BC06 mem[R[6]] <- R[C] a[n] = c
|
|
17: 1BB1 R[B] <- R[B] + R[1] n++
|
|
18: C013 goto 13 }
|
|
|
|
// Print out results in reverse order
|
|
19: CB20 if (R[B] == 0) goto 20 while (n != 0) {
|
|
1A: 16AB R[6] <- R[A] + R[B] a + n
|
|
1B: 2661 R[6] <- R[6] - R[1] a + n - 1
|
|
1C: AC06 R[C] <- mem[R[6]] c = a[n-1]
|
|
1D: 9CFF write R[C] print c
|
|
1E: 2BB1 R[B] <- R[B] - R[1] n--
|
|
1F: C019 goto 19 }
|
|
20: 0000 halt
|