Created
May 2, 2020 21:38
-
-
Save fami-com/ac1fce224813c807193fe9c74c114509 to your computer and use it in GitHub Desktop.
An implementation of an elementary cellular automaton (Rule 30/90/110/arbitrary) in fasm for windows.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
format PE64 CONSOLE | |
entry start | |
include 'win64a.inc' | |
section '.data' data readable writeable | |
State dq 0x0000000100000000 | |
String db 65 dup(0) | |
Rule db 30 | |
section '.code' code executable | |
proc NextState state:QWORD, rules:BYTE | |
xor rax, rax | |
mov r8, rcx | |
mov rcx, 65 | |
.loop: | |
rol r8, 1 | |
mov r9, r8 | |
and r9, 7 | |
bt rdx, r9 | |
rcl rax, 1 | |
loop .loop | |
ret | |
endp | |
proc StrBin dest:QWORD, src:QWORD | |
push rdi | |
mov rdi, rcx | |
mov rcx, 64 | |
.loop: | |
shl rdx, 1 | |
setc al | |
add al, 0x30 | |
stosb | |
loop .loop | |
mov al, 0 | |
stosb | |
pop rdi | |
ret | |
endp | |
section '.code' code readable writeable executable | |
start: | |
.loop: | |
fastcall StrBin, String, [State] | |
invoke puts, String | |
.read: | |
invoke getch | |
cmp rax, 27 | |
je .exit | |
cmp rax, 0 | |
jne .outside | |
jmp .read | |
.outside: | |
fastcall NextState, [State], [Rule] | |
mov [State], rax | |
jmp .loop | |
.exit: | |
invoke ExitProcess, 0 | |
section '.idata' import data readable writeable | |
library kernel32,'kernel32.dll',\ | |
msvcrt,'msvcrt.dll' | |
import kernel32,\ | |
ExitProcess,'ExitProcess',\ | |
Sleep,'Sleep' | |
import msvcrt,\ | |
puts,'puts',\ | |
getch,'_getch' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment