;; GOD CELL ;; BY RICHARD W.M. JONES 00001: ; Marks beginning of the cell. JMPF ~00011 ; Jump to start of the cell code ; proper. 00010: ; Marks start of local variables. DW 4 ; Local variable storage. ; This is the main cell program. 00011: ; Marks the start of the cell code. ; When debugging, use this canard to detect stack underflows. ;MOVE 65535,A ;PUSH A FINDB ~00010 ; Find beginning of local variables. MOVE I,A ; Add length of label. ADD 5,A MOVE A,B ; Initialize base register. FINDB ~00001 ; Find beginning address of cell. MOVE I,A STORE A,0 ; Save it for later. FINDF ~01111 ; Find end address of cell. MOVE I,A ADD 5,A ; Add length of final label. STORE A,1 ; Save it for later. CALLF ~00100 ; Call subroutine to subtract ; var 0 from var 1 and store in var 2. LOAD 2,A ; Load the computed length. MALLOC ; Allocate memory for the daughter. MOVE I,A JMPZB ~00011 ; If allocation failed, start again. STORE A,3 ; Store the daughter's address in 3. CALLF ~00110 ; Call subroutine to do the copy. DIVIDE ; Break off the daughter cell. JMPB ~00011 ; Repeat forever! ; This subroutine subtracts var 0 from var 1 and stores the ; resulting value in var 2. 00100: LOAD 1,A ; Copy var 1 into var 2 STORE A,2 LOAD 0,A ; A <- amount to subtract 00101: JMPZF ~01001 ; Loop until A == 0 PUSH A LOAD 2,A ; Subtract 1 from var 2. DEC A STORE A,2 POP A DEC A JMPB ~00101 01001: RET 5 ; This subroutine copies var 2 bytes from [var 0] to [var 3] (ie. ; from the mother to the daughter). 00110: LOAD 2,A ; Number of bytes to copy. 00111: JMPZF ~01000 ; Leave loop when A == 0. PUSH A LOAD 0,A ; Get source address. MOVE A,I MOVE [I],A ; Get item to copy from source. PUSH A LOAD 3,A ; Get destination address. MOVE A,I POP A MOVE A,[I] ; Store item at destination addr. LOAD 0,A ; Increment source address. INC A STORE A,0 LOAD 3,A ; Increment destination address. INC A STORE A,3 POP A DEC A JMPB ~00111 01000: RET 5 01111: ; Marks end of the cell.