Accueil > > > GAME OF LIFE
GAME OF LIFE
Information sur la source
Description
Source
- ;The Game of Life is a cellular automata program, where each pixel on the screen
- ;will live or die in each generation based upon some arbitrary rules.
- ;Specifically, if a pixel has three neighbors, it lives to the next generation.
- ;If an empty cell has two neighbors, it becomes populated in the next generation.
- ;Otherwise, that pixel gets cleared for the next generation. In this program, we
- ;generate an initial screen image using the paint program from last class. We
- ;then make a future image of the video screen in our offscreen buffer, then when
- ;complete, copy to the video.
- ; source file for assembling to binary files
- ; build with:
- ; nasmw -f bin -o life.com life.asm
-
- org 100h
-
- section .text
-
- mov ax,13h
- int 10h ;256 color graphics mode
-
- mov ax,0a000h ;video buffer
- mov es,ax ;pointer for segment
- xor di,di ;offset
- mov cx,32000 ;number of words in video
- xor ax,ax ;clear AX
- rep stosw ;and store in video buffer
-
- mov ax,1 ;show mouse
- int 33h
-
- M0:
- mov ax,0b21h ;check keyboard status
- int 21h
- cmp al,0 ;are any characters pending?
- jne Game
-
- mov ax,3 ;get mouse status call
- int 33h
- cmp bx,0 ;is mouse up
- je M0 ;loop till pressed
-
- M1: mov ax,0b21h ;check keyboard status
- int 21h
- cmp al,0 ;are any characters pending?
- jne Game
-
- mov ax,3 ;get fresh copy of mouse coordinates
- int 33h
-
- mov ah,0ch ;write dot at coordinate
- mov al,1 ;color value
- shr cx,1 ;mouse scale offset fix
- dec cx ;escape mouse overwrite in win95
- int 10h
-
- mov ax,3
- int 33h
- cmp bx,0
- jne M1
-
- mov ax,0b21h ;check keyboard status
- int 21h
- cmp al,0 ;are any characters pending?
- je M0
-
- Game:
-
- mov ax,2 ;hide cursor function
- int 33h
- mov cx,100
-
- G1: mov ax,ds ;segment address
- mov es,ax ;now pointed to by ES
- push cx
- mov di,Screen
- mov cx,32000 ;number of words in video
- xor ax,ax ;clear AX
- rep stosw ;and store in video buffer (cleared)
-
- mov word [X],318 ;X goes from 1 to 318 (0 to 319 excluding boundaries)
- G2: mov word [Y],198 ;Y goes from 1 to 198 (0 to 199 excluding boundaries)
- G3: call Count ;count of neighbors lands in AX
- cmp AX,2 ;survive threshold
- jne G4 ;if not, check for three
- call GetDot ;do we have a current cell here to survive?
- je G4 ;if not, don't set
- call SetDot ;make color 2
- G4: cmp AX,3 ;check generation
- jne G5 ;no spawn if not 3
- call SetDot ;else set color 3
- G5: dec word[Y] ;move up
- jne G3 ;if not at top
- dec word[X] ;move left
- jne G2 ;if not at left
-
- mov ax,0a000h ;video buffer
- mov es,ax
- xor di,di ;destination pointer
-
- mov si,Screen ;source pointer
-
- mov cx,32000
- rep movsw ;copy to video
-
- mov ax,ds ;reset extra segment to data segment
- mov es,ax
-
- pop cx
- loop G1
-
- mov ax,3 ;put video back into text mode
- int 10h
- mov ax,4c00h
- int 21h
-
- GetDot: ;check for cell on screen at coordinates in X and Y
- push ax
- push bx
- push dx
- push es
-
- mov ax,0a000h ;video segment
- mov es,ax ;pointer
- mov ax,[Y] ;y coord
- mov bx,320 ;dots per Y
- mul bx ;DX:AX has answer (DX = 0, AX = row offset)
- add ax,[X] ;add X coordinate
- mov bx,ax ;use BX as pointer
- mov al,[es:bx] ;get
- cmp al,0 ;is cell zero? return in flag
-
- pop es
- pop dx
- pop bx
- pop ax
- ret
-
- SetDot: ;mov al to coordinates in X and Y
- push ax
- push bx
- push dx
-
- push ax ;store data on stack
- mov ax,[Y] ;y coord
- mov bx,320 ;dots per Y
- mul bx ;DX:AX has answer (DX = 0, AX = row offset)
- add ax,[X] ;add X coordinate
- mov bx,ax ;use BX as pointer
- add bx,Screen ;add in offset of screen buffer
- pop ax ;get count value as color
- mov [es:bx],al ;store
-
- pop dx
- pop bx
- pop ax
- ret
-
- Count:
- push bx
- push cx
- push dx
- push es
-
- mov ax,0a000h ;video buffer segment
- mov es,ax
- mov ax,[Y] ;y coord
- mov bx,320 ;dots per Y
- mul bx ;DX:AX has answer (DX = 0, AX = row offset)
- add ax,[X] ;add X coordinate
- mov bx,ax ;use BX as pointer
- xor ax,ax ;clear AX
-
- xor dx,dx ;just a convenient zero
-
- ; 2 3 4
- ; 0 1
- ; 5 6 7
-
- cmp dl,[es:bx-1] ;check left
- je C1 ;if clear, skip add
- inc ax
-
- C1: cmp dl,[es:bx+1] ;check right
- je C2 ;if clear, skip add
- inc ax
-
- C2: cmp dl,[es:bx-321] ;check top left
- je C3 ;if clear, skip add
- inc ax
-
- C3: cmp dl,[es:bx-320] ;check above
- je C4 ;if clear, skip add
- inc ax
-
- C4: cmp dl,[es:bx-319] ;check upper right
- je C5 ;if clear, skip add
- inc ax
-
- C5: cmp dl,[es:bx+319] ;check below left
- je C6 ;if clear, skip add
- inc ax
-
- C6: cmp dl,[es:bx+320] ;check below
- je C7 ;if clear, skip add
- inc ax
-
- C7: cmp dl,[es:bx+321] ;check below right
- je C8 ;if clear, skip add
- inc ax
-
-
- C8: pop es
- pop dx
- pop cx
- pop bx
- ret
-
- section .data
- X dw 0 ;X coordinate during regeneration
- Y dw 0 ;Y coordinate during regeneration
-
- section .bss
- Screen resb 64000 ;copy of screen in mode 13H
;The Game of Life is a cellular automata program, where each pixel on the screen
;will live or die in each generation based upon some arbitrary rules.
;Specifically, if a pixel has three neighbors, it lives to the next generation.
;If an empty cell has two neighbors, it becomes populated in the next generation.
;Otherwise, that pixel gets cleared for the next generation. In this program, we
;generate an initial screen image using the paint program from last class. We
;then make a future image of the video screen in our offscreen buffer, then when
;complete, copy to the video.
; source file for assembling to binary files
; build with:
; nasmw -f bin -o life.com life.asm
org 100h
section .text
mov ax,13h
int 10h ;256 color graphics mode
mov ax,0a000h ;video buffer
mov es,ax ;pointer for segment
xor di,di ;offset
mov cx,32000 ;number of words in video
xor ax,ax ;clear AX
rep stosw ;and store in video buffer
mov ax,1 ;show mouse
int 33h
M0:
mov ax,0b21h ;check keyboard status
int 21h
cmp al,0 ;are any characters pending?
jne Game
mov ax,3 ;get mouse status call
int 33h
cmp bx,0 ;is mouse up
je M0 ;loop till pressed
M1: mov ax,0b21h ;check keyboard status
int 21h
cmp al,0 ;are any characters pending?
jne Game
mov ax,3 ;get fresh copy of mouse coordinates
int 33h
mov ah,0ch ;write dot at coordinate
mov al,1 ;color value
shr cx,1 ;mouse scale offset fix
dec cx ;escape mouse overwrite in win95
int 10h
mov ax,3
int 33h
cmp bx,0
jne M1
mov ax,0b21h ;check keyboard status
int 21h
cmp al,0 ;are any characters pending?
je M0
Game:
mov ax,2 ;hide cursor function
int 33h
mov cx,100
G1: mov ax,ds ;segment address
mov es,ax ;now pointed to by ES
push cx
mov di,Screen
mov cx,32000 ;number of words in video
xor ax,ax ;clear AX
rep stosw ;and store in video buffer (cleared)
mov word [X],318 ;X goes from 1 to 318 (0 to 319 excluding boundaries)
G2: mov word [Y],198 ;Y goes from 1 to 198 (0 to 199 excluding boundaries)
G3: call Count ;count of neighbors lands in AX
cmp AX,2 ;survive threshold
jne G4 ;if not, check for three
call GetDot ;do we have a current cell here to survive?
je G4 ;if not, don't set
call SetDot ;make color 2
G4: cmp AX,3 ;check generation
jne G5 ;no spawn if not 3
call SetDot ;else set color 3
G5: dec word[Y] ;move up
jne G3 ;if not at top
dec word[X] ;move left
jne G2 ;if not at left
mov ax,0a000h ;video buffer
mov es,ax
xor di,di ;destination pointer
mov si,Screen ;source pointer
mov cx,32000
rep movsw ;copy to video
mov ax,ds ;reset extra segment to data segment
mov es,ax
pop cx
loop G1
mov ax,3 ;put video back into text mode
int 10h
mov ax,4c00h
int 21h
GetDot: ;check for cell on screen at coordinates in X and Y
push ax
push bx
push dx
push es
mov ax,0a000h ;video segment
mov es,ax ;pointer
mov ax,[Y] ;y coord
mov bx,320 ;dots per Y
mul bx ;DX:AX has answer (DX = 0, AX = row offset)
add ax,[X] ;add X coordinate
mov bx,ax ;use BX as pointer
mov al,[es:bx] ;get
cmp al,0 ;is cell zero? return in flag
pop es
pop dx
pop bx
pop ax
ret
SetDot: ;mov al to coordinates in X and Y
push ax
push bx
push dx
push ax ;store data on stack
mov ax,[Y] ;y coord
mov bx,320 ;dots per Y
mul bx ;DX:AX has answer (DX = 0, AX = row offset)
add ax,[X] ;add X coordinate
mov bx,ax ;use BX as pointer
add bx,Screen ;add in offset of screen buffer
pop ax ;get count value as color
mov [es:bx],al ;store
pop dx
pop bx
pop ax
ret
Count:
push bx
push cx
push dx
push es
mov ax,0a000h ;video buffer segment
mov es,ax
mov ax,[Y] ;y coord
mov bx,320 ;dots per Y
mul bx ;DX:AX has answer (DX = 0, AX = row offset)
add ax,[X] ;add X coordinate
mov bx,ax ;use BX as pointer
xor ax,ax ;clear AX
xor dx,dx ;just a convenient zero
; 2 3 4
; 0 1
; 5 6 7
cmp dl,[es:bx-1] ;check left
je C1 ;if clear, skip add
inc ax
C1: cmp dl,[es:bx+1] ;check right
je C2 ;if clear, skip add
inc ax
C2: cmp dl,[es:bx-321] ;check top left
je C3 ;if clear, skip add
inc ax
C3: cmp dl,[es:bx-320] ;check above
je C4 ;if clear, skip add
inc ax
C4: cmp dl,[es:bx-319] ;check upper right
je C5 ;if clear, skip add
inc ax
C5: cmp dl,[es:bx+319] ;check below left
je C6 ;if clear, skip add
inc ax
C6: cmp dl,[es:bx+320] ;check below
je C7 ;if clear, skip add
inc ax
C7: cmp dl,[es:bx+321] ;check below right
je C8 ;if clear, skip add
inc ax
C8: pop es
pop dx
pop cx
pop bx
ret
section .data
X dw 0 ;X coordinate during regeneration
Y dw 0 ;Y coordinate during regeneration
section .bss
Screen resb 64000 ;copy of screen in mode 13H
Sources de la même categorie
Commentaires et avis
|
Derniers Blogs
TECHDAYS PARIS 2012 : NOUVELLES TENDANCES DU POSTE DE TRAVAIL - BRING YOUR OWN PCTECHDAYS PARIS 2012 : NOUVELLES TENDANCES DU POSTE DE TRAVAIL - BRING YOUR OWN PC par ROMELARD Fabrice
Speakers: Thierry Rapatout, Antoine Petit et Xavier Trebbia Cette session entre dans le cadre des RDV Décideurs des TechDays 2012, elle est liée à la consumérisation de l'IT et la mise en place du "DeskTop as a Service" dans de plus en ...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice TECHDAYS PARIS 2012 : SYSTEM CENTER SERVICE MANAGER 2012 VUE D'ENSEMBLETECHDAYS PARIS 2012 : SYSTEM CENTER SERVICE MANAGER 2012 VUE D'ENSEMBLE par ROMELARD Fabrice
Speakers: Julien Marechal, Gautier Confiant, Sébastien MEYER La session débute par le positionnement de la solution System Center par rapport aux concepts d'organisation ITIL. Le portail du catalogue de se...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice TECHDAYS PARIS 2012 : PLEINIèRE SECOND JOURTECHDAYS PARIS 2012 : PLEINIèRE SECOND JOUR par ROMELARD Fabrice
Après une première journée dédiée aux développeurs, cette seconde journée est dédiée au monde des entreprises et de ses applications. Ainsi, cette pleinière est dédiée à faire un 360 de l'évolution des applications Business aux demandes ac...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice TECHDAYS PARIS 2012 : RETOUR D'EXPéRIENCE SUR LA MISE EN PLACE D'UN CLOUD PRIVéTECHDAYS PARIS 2012 : RETOUR D'EXPéRIENCE SUR LA MISE EN PLACE D'UN CLOUD PRIVé par ROMELARD Fabrice
Speaker : Guillaume Rochette Cette session est dédiée à fournir le retour sur la mise en place d'un cloud privé (IaaS) par Osiatis pour son compte ou celui de ses clients. Ce projet s'est déroulé sur 4 mois et a permis de faire évoluer...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice TECHDAYS PARIS 2012 : COMMENT SHAREPOINT A SAUVé MES TECHDAYSTECHDAYS PARIS 2012 : COMMENT SHAREPOINT A SAUVé MES TECHDAYS par ROMELARD Fabrice
Speakers : Lionel Limozin et Alain Marty La session commence par une découverte de SharePoint à travers la mise en place d'un environnement SharePoint pour la gestion des Sessions animées par BeWise. Le besoin est très ba...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice
Logiciels
Academy System (17.2.1.0)ACADEMY SYSTEM (17.2.1.0)Logiciel de gestion des établissements.
- élèves/étudiants (inscription, dossier, absence...)
-... Cliquez pour télécharger Academy System Easy-Planning (1.0.0.1)EASY-PLANNING (1.0.0.1)Basé sur les mêmes principes que MyPlanning, Easy-Planning permet de créer des plannings sous la ... Cliquez pour télécharger Easy-Planning COLLECTOR PLUS (3.00B)COLLECTOR PLUS (3.00B)COLLECTOR PLUS version 3.00B est un logiciel utilisant une base de données alimentée par :
- L... Cliquez pour télécharger COLLECTOR PLUS PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V7.4)PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V7.4)PONAMEDIA TV DEVIENS HELLLOOO FLASH
LA TV SUR VOTRE ORDINATEUR.
Toute une plateforme Multi... Cliquez pour télécharger PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO LettresFaciles 2011 (8.0.0.1)LETTRESFACILES 2011 (8.0.0.1)LettresFaciles est un logiciel facilitant la création et la rédaction de lettres types.
Son inte... Cliquez pour télécharger LettresFaciles 2011
|