SMAL32 (rev 9/03) RULES -- compute the next 10:22:17 Page 1 Fri Nov 12 2004 1 TITLE RULES -- compute the next state for one cell 2 3 ; The population of the adjoining cells are counted, using a path 4 ; described by the vector rulvec to find and count the neighbors, 5 ; and then using maxpop and minpop to determine the next state. 6 ; The next state is recorded in a high bit of each cell, so that 7 ; it can be shifted down to become the current state later. 8 ; ---------------------------------- 9 10 USE "hawk.macs" 11 USE "life.h" +000000:+00000000 12 13 INT RULES 14 15 ; ---------------------------------- 16 ; receiving sequence assumptions 17 RULES: 18 ; expects R1 = return address, never uses R1, never uses stack 19 ; expects R3 = pcurrent pointer to current cell 20 ; uses R4-R7 21 ; returns nothing 22 ; current cell updated by addition of SURVIVE if alive in next state 23 MOVE R4,R3 ; pneighbor = pcurent +000004: F4F3 24 LEA R5,RULVEC ; pdelta = rulvec +000006: F570 003A 25 LIS R6,0 ; neighbors = 0 +00000A: D600 26 RULLP: ; while (true) { -- loop looking at neighbors 27 ; here, R3 is pcurrent 28 ; here, R4 is pneighbor 29 ; here, R5 is pdelta 30 ; here, R6 is neighbors 31 ; here, R7 is free 32 LOADSCC R7,R5 ; delta = *pdelta +00000C: F7C5 33 BZS RULLQT ; if (delta = 0) exit +00000E: 0207 34 ADD R4,R4,R7 ; pneighbor = pneighbor + delta +000010: 3447 35 36 LOADS R7,R4 +000012: F7D4 37 EXTB R7,R7,R4 ; neighbor = *pneighbor +000014: 5774 38 TRUNC R7,1 ; neighbor = neighbor & 1 (just LSB) +000016: 17F1 39 ADD R6,R6,R7 ; neighbors = neighbors + neighbor +000018: 3667 40 41 ADDSI R5,4 ; pdelta++ +00001A: 15C4 42 BR RULLP +00001C: 00F7 43 RULLQT: ; } 44 45 ; now, we apply rule for determining next state 46 LOADS R7,R3 +00001E: F7D3 47 EXTB R4,R7,R3 ; current = *pcurrent +000020: 5473 48 LIS R5,0 ; next = 0 -- default next state is death +000022: D500 49 ; here, R3 is pcurrent 50 ; here, R4 is current 51 ; here, R5 is the next state 52 ; here, R6 is the count of neighbors 53 ; here, R7 is the word into which current will be stuffed 54 55 CMPI R6,MINPOP +000024: F066 FFF7 56 BLT RULQT ; if ((neighbors >= minpop) SMAL32 (rev 9/03) RULES -- compute the next 10:22:17 Page 2 Fri Nov 12 2004 +000028: 0509 57 CMPI R6,MAXPOP +00002A: F066 FFF0 58 BGT RULQT ; && (neighbors <= maxpop)) { +00002E: 0E06 59 CMPI R6,MINBIRTH +000030: F066 FFF4 60 BLT RULLIV ; if (neighbors >= minbirth) { +000034: 0502 61 LIS R5,SURVIVE ; next = survive -- force a birth +000036: D510 62 BR RULQT +000038: 0001 63 RULLIV: ; } else { 64 MOVESL R5,R4,GENSHIFT ; next = current << genshift +00003A: B544 65 RULQT: ; } } 66 67 OR R4,R5 +00003C: 14A5 68 STUFFB R7,R4,R3 +00003E: 7743 69 STORES R7,R3 ; *pcurrent = current | next +000040: F7A3 70 71 JUMPS R1 ; return +000042: F0B1 72 73 ; ---------------------------------- 74 75 ; neighbor counts for Conway's game of life: 76 77 MINPOP = 9 ; death for fewer neighbors than this 78 MAXPOP = 16 ; birth at this, death at greater 79 MINBIRTH= 12 ; birth from this to MAXPOP 80 81 ; ---------------------------------- 82 ; zero terminated array of address increments from cell to cell 83 ; adding these increments to the address of a cell, in sequence, 84 ; visits all the neighbors of that cell 85 86 ALIGN 4 87 RULVEC: 88 ; 4 cardinal directions, starting at origin, ending above +000044: 00000001 89 W RIGHT +000048: 0000007F 90 W DOWN+LEFT +00004C: FFFFFF7F 91 W UP+LEFT +000050: FFFFFF81 92 W UP+RIGHT 93 ; 4 cardinal directions, starting above, ending above +000054: 00000081 94 W DOWN+RIGHT +000058: 0000007F 95 W DOWN+LEFT +00005C: FFFFFF7F 96 W UP+LEFT +000060: FFFFFF81 97 W UP+RIGHT 98 ; 4 cardinal directions, starting above, ending above +000064: 00000081 99 W DOWN+RIGHT +000068: 0000007F 100 W DOWN+LEFT +00006C: FFFFFF7F 101 W UP+LEFT +000070: FFFFFF81 102 W UP+RIGHT 103 ; 4 cardinal directions, starting above, ending above +000074: 00000081 104 W DOWN+RIGHT +000078: 0000007F 105 W DOWN+LEFT +00007C: FFFFFF7F 106 W UP+LEFT +000080: FFFFFF81 107 W UP+RIGHT 108 ; 4 diagonals, starting above, ending above left +000084: 00000001 109 W RIGHT +000088: 00000100 110 W DOWN+DOWN +00008C: FFFFFFFE 111 W LEFT+LEFT +000090: FFFFFF00 112 W UP+UP SMAL32 (rev 9/03) RULES -- compute the next 10:22:17 Page 3 Fri Nov 12 2004 113 ; 4 diagonals, starting above left, ending above left +000094: 00000002 114 W RIGHT+RIGHT +000098: 00000100 115 W DOWN+DOWN +00009C: FFFFFFFE 116 W LEFT+LEFT +0000A0: FFFFFF00 117 W UP+UP 118 ; 4 super-cardinals, starting above left, ending way left +0000A4: FFFFFF81 119 W UP+RIGHT +0000A8: 00000102 120 W DOWN+DOWN+RIGHT+RIGHT +0000AC: 000000FE 121 W DOWN+DOWN+LEFT+LEFT +0000B0: FFFFFEFE 122 W UP+UP+LEFT+LEFT 123 ; end of list +0000B4: 00000000 124 W 0 125 126 ; increments from a cell on the board to its neighbors 127 RIGHT = 1 128 LEFT = -1 129 DOWN = WIDTH 130 UP = -WIDTH 131 132 ; ---------------------------------- 133 END no errors