I have tried to code COnway's Game of Life. But it doesn't seem to work...
.MODEL TINY
.CODE
;.STARTUP
EntryPoint:            mov AX,0013h                                            ;Videomode 13h (320 * 200)
                        int 10h                                                ;Switch videomode to 13h

                        mov AX,3000h                                            ;Set AX = 3000h
                        mov ES,AX                                              ;Set ES = AX
                        xor DI,DI                                              ;Set DI = 0000h
                                                                                ;ES:DI points to current field
                        mov AL,0Fh                                              ;Code for dead cell
                        mov CX,140h * 0C8h                                      ;Number of cells on the field
                        rep stosb                                              ;Kill all cells


                        mov DI,320 * 40 + 15
                        mov AL,00h
                        stosb
                        stosb
                        stosb
                        sub DI,321
                        stosb
                        sub DI,322
                        stosb


                        mov AX,0A000h
                        mov ES,AX
                        xor DI,DI
                        mov AX,03000h
                        mov DS,AX
                        xor SI,SI
                        mov CX,320*200
                        rep movsb

                        xor AX,AX
                        int 16h


Begin:                  mov AX,3000h                                            ;Set AX = 3000h
                        mov DS,AX                                              ;Set DS = AX
                        xor SI,SI                                              ;Set SI = 0000h
                                                                                ;DS:SI points to the current field
                        mov AX,4000h                                            ;Set AX = 4000h
                        mov ES,AX                                              ;Set ES = AX
                        xor DI,DI                                              ;Set DI = 0000h
                                                                                ;ES:DI points to the temporary field
CircleOfLife:          xor CX,CX                                              ;Set CX = 0000h. Used to count the neighbours of the current cell
                        push SI                                                ;Save current cell
                        sub SI,141h                                            ;Subtract 141h from current cell; SI selects now the cell located NW of the original cell
                        jc NoNWNeighbour                                        ;If below zero, then there can be no neighbour
                        lodsb                                                  ;Load the cell NW of the current cell into AL
                        or AL,AL                                                ;Check whether it's alive
                        jne NoNWNeighbour                                      ;If not, then there's no neighbour
                        inc CX                                                  ;If yes, then increase the number of neighbours
NoNWNeighbour:          pop SI                                                  ;Restore current cell
                        push SI
                        sub SI,140h
                        jc NoNNeighbour
                        lodsb
                        or AL,AL
                        jne NoNNeighbour
                        inc CX
NoNNeighbour:          pop SI
                        push SI
                        sub SI,139h
                        jc NoNENeighbour
                        lodsb
                        or AL,AL
                        jne NoNENeighbour
                        inc CX
NoNENeighbour:          pop SI
                        push SI
                        dec SI
                        jc NoWNeighbour
                        lodsb
                        or AL,AL
                        jne NoWNeighbour
                        inc CX
NoWNeighbour:          pop SI
                        push SI
                        inc SI
                        jc NoENeighbour
                        cmp SI,140h * 0C8h
                        ja NoENeighbour
                        lodsb
                        or AL,AL
                        jne NoENeighbour
                        inc CX
NoENeighbour:          pop SI
                        push SI
                        add SI,139h
                        jc NoSWNeighbour
                        cmp SI,140h * 0C8h
                        ja NoSWNeighbour
                        lodsb
                        or AL,AL
                        jne NoSWNeighbour
                        inc CX
NoSWNeighbour:          pop SI
                        push SI
                        add SI,140h
                        jc NoSNeighbour
                        cmp SI,140h * 0C8h
                        ja NoSNeighbour
                        lodsb
                        or AL,AL
                        jne NoSNeighbour
                        inc CX
NoSNeighbour:          pop SI
                        push SI
                        add SI,141h
                        jc NoSENeighbour
                        cmp SI,140h * 0C8h
                        ja NoSENeighbour
                        lodsb
                        or AL,AL
                        jne NoSENeighbour
                        inc CX
NoSENeighbour:          pop SI
                        lodsb
                        or AL,AL
                        jne DeadCell
                        cmp CX,02h
                        jb CellDies
                        cmp CX,03h
                        ja CellDies
                        jmp Application
CellDies:              mov AL,0Fh
                        jmp Application
DeadCell:              cmp CX,03h
                        jne NoRebirth
                        xor AL,AL
                        jmp Application
NoRebirth:              mov AL,0Fh
Application:            stosb
                        cmp SI,140h * 0C8h
                        jbe CircleOfLife

                        mov AX,4000h
                        mov DS,AX
                        xor SI,SI
                        mov AX,3000h
                        mov ES,AX
                        xor DI,DI
                        mov CX,140h * 0C8h
                        rep movsb

                        xor SI,SI
                        mov AX,0A000h
                        mov ES,AX
                        xor DI,DI
                        mov CX,140h * 0C8h
                        rep movsb

                        xor AX,AX
                        int 16h


                        jmp Begin
END

Can anyone help me?!?
Info: CX contains number of neighbours
Current field @ 3000:0000
Temporary field @ 4000:0000
Dead Cell = 0Fh, Living Cell = 00h.
Posted on 2006-09-23 12:29:46 by Firefall
Well... I got the solution... Before 140h comes 13Fh, not 139h. SOmetimes I wish I had sixteen fingers... Here goes the final code (It works):
.MODEL TINY
.CODE
.STARTUP

Cell_Alive              EQU 00h
Cell_Dead              EQU 0Fh

EntryPoint:            mov AX,0013h                                            ;Videomode 13h (320 * 200)
                        int 10h                                                ;Switch videomode to 13h

                        mov AX,3000h                                            ;Set AX = 3000h
                        mov ES,AX                                              ;Set ES = AX
                        xor DI,DI                                              ;Set DI = 0000h
                                                                                ;ES:DI points to current field
                        mov AL,Cell_Dead                                        ;Draw dead cells
                        mov CX,140h * 0C8h                                      ;Number of cells on the field
                        rep stosb                                              ;Kill all cells on current field

;###############################################
;DRAW GLIDER
                        mov DI,320 * 40 + 15
                        mov AL,Cell_Alive
                        stosb
                        stosb
                        stosb
                        sub DI,321
                        stosb
                        sub DI,322
                        stosb
;###############################################


Begin:                  mov AX,3000h                                            ;Set AX = 3000h
                        mov DS,AX                                              ;Set DS = AX
                        xor SI,SI                                              ;Set SI = 0000h
                        mov AX,0A000h                                          ;Set AX = A000h
                        mov ES,AX                                              ;Set ES = AX
                        xor DI,DI                                              ;Set DI = 0000h
                        mov CX,140h * 0C8h / 02h                                ;Number of cells on the field / 2
                        rep movsw                                              ;Copy two cells at once

                        xor SI,SI                                              ;Set SI = 0000h
                                                                                ;DS:SI points to the current field
                        mov AX,4000h                                            ;Set AX = 4000h
                        mov ES,AX                                              ;Set ES = AX
                        xor DI,DI                                              ;Set DI = 0000h
                                                                                ;ES:DI points to the temporary field
CircleOfLife:          xor CX,CX                                              ;Set CX = 0000h. Used to count the neighbours of the current cell
                        push SI                                                ;Save current cell
                        sub SI,141h                                            ;Subtract 141h from current cell; SI selects now the cell located NW of the original cell
                        jc NoNWNeighbour                                        ;If below zero, then there can be no neighbour
                        lodsb                                                  ;Load the cell NW of the current cell into AL
                        cmp AL,Cell_Alive                                      ;Check whether it's alive
                        jne NoNWNeighbour                                      ;If not, then there's no neighbour
                        inc CX                                                  ;If yes, then increase the number of neighbours
NoNWNeighbour:          pop SI                                                  ;Restore current cell
                        push SI
                        sub SI,140h
                        jc NoNNeighbour
                        lodsb
                        cmp AL,Cell_Alive
                        jne NoNNeighbour
                        inc CX
NoNNeighbour:          pop SI
                        push SI
                        sub SI,13Fh
                        jc NoNENeighbour
                        lodsb
                        cmp AL,Cell_Alive
                        jne NoNENeighbour
                        inc CX
NoNENeighbour:          pop SI
                        push SI
                        dec SI
                        jc NoWNeighbour
                        lodsb
                        cmp AL,Cell_Alive
                        jne NoWNeighbour
                        inc CX
NoWNeighbour:          pop SI
                        push SI
                        inc SI
                        cmp SI,140h * 0C8h
                        ja NoENeighbour
                        lodsb
                        cmp AL,Cell_Alive
                        jne NoENeighbour
                        inc CX
NoENeighbour:          pop SI
                        push SI
                        add SI,13Fh
                        cmp SI,140h * 0C8h
                        ja NoSWNeighbour
                        lodsb
                        cmp AL,Cell_Alive
                        jne NoSWNeighbour
                        inc CX
NoSWNeighbour:          pop SI
                        push SI
                        add SI,140h
                        cmp SI,140h * 0C8h
                        ja NoSNeighbour
                        lodsb
                        cmp AL,Cell_Alive
                        jne NoSNeighbour
                        inc CX
NoSNeighbour:          pop SI
                        push SI
                        add SI,141h
                        cmp SI,140h * 0C8h
                        ja NoSENeighbour
                        lodsb
                        cmp AL,Cell_Alive
                        jne NoSENeighbour
                        inc CX
NoSENeighbour:          pop SI
                        lodsb
                        cmp AL,Cell_Alive
                        jne DeadCell
                        cmp CX,02h
                        jb CellDies
                        cmp CX,03h
                        ja CellDies
                        jmp Application
CellDies:              mov AL,Cell_Dead
                        jmp Application
DeadCell:              cmp CX,03h
                        jne NoRebirth
                        mov AL,Cell_Alive
                        jmp Application
NoRebirth:              mov AL,Cell_Dead
Application:            stosb
                        cmp SI,140h * 0C8h
                        jbe CircleOfLife

                        mov AX,4000h
                        mov DS,AX
                        xor SI,SI
                        mov AX,3000h
                        mov ES,AX
                        xor DI,DI
                        mov CX,140h * 0C8h / 02h
                        rep movsw

                        jmp Begin
END
Posted on 2006-09-23 16:48:08 by Firefall
Mine dies out quite quickly most times.

You can perpetuate it with

CircleOfLife
xor cx,cx ;Set CX = 0000h. Used
add bp,1
cmp bp,FFFF
ifz-add cx,1
;to count the neighbours of the
;current cell
push si    ;Save current cell
Posted on 2006-09-24 07:53:50 by eek
Well it develops rather quick (I'd say at least 10 generations/second).
You can put some hlt before the jmp Begin to slow it down, or simply: draw more structures by replacing the Glider-Part with whatever you like.

I don't understand your code, can you explain a little more?
Posted on 2006-09-25 04:42:26 by Firefall
If that's me your asking, all I'm doing is seeding in an extra 1 to cx every 65,000 cycles to keep the activity going perpetually.
I also removed int16.

Just me messing about.

I'm using an old P1500 so it looks fine for me to run it non-stop, maybe it looks daft on a decent machine.
Posted on 2006-09-25 05:35:14 by eek
Huh? You mean you're pretending more neighbour cells? :D Cheater!
Posted on 2006-09-25 09:54:58 by Firefall
Just playing at God.
The answer to life the universe and everything is FFFF...not 42.
8)
Posted on 2006-09-25 11:40:20 by eek
And the answer to superpopulation is 0x0000 ;)
Posted on 2006-09-25 16:13:28 by Firefall
Genetic algorithms have always interested me.
My first foray in this field involved a simulator for 'flocking behaviour', but lately I've been trying to marry genetic algorithms with a self-organizing FFBP neural network, with promising results.
Each neuron represents one 'chromosome', and only the 'fittest' neurons are propagated into the next generation, so we have a kind of genetic filter representing one generation of a 'asexually propagated lifeform'..
My next move will be to implement several lifeforms (several neural networks), and use a modified flocking behaviour to select 'mating pairs' from which the subsequent generation will be derived, with a little randomness thrown into the mix to ensure that we retain biodiversity.
I'm actually interested more in evolved neural networks than I am in the game of life in this case.
Posted on 2006-09-27 04:51:03 by Homer
@Homer: Nice, sounds cool :) Do you write that in ASM, too?
@Everyone: DO you think my code's correct? I have drawn a random pattern and executed it, and everything looked normal, except the fact that there seems to be one single pixel on the right border which permanently dies and gets reborn, although it has no living neighbour cells...
Posted on 2006-09-27 04:56:47 by Firefall