Conway's Game of Life

Sorry, it must have changed the format accidentally. And I'm coding in assembly for academic reasons
call #rdmsd ;call #gldr ;call #gldrg call #conway

endloop jmp endloop

conway

    ret

gldr mov #0x0002, &0x020A mov #0x00A, &0x0212 mov #0x006, &0x021A ret

gldrg mov.b #0x0040, &0x0213 mov.b #0x0001, &0x021a mov.b #0x0040, &0x021b mov.b #0x0006, &0x0221 mov.b #0x0006, &0x0222 mov.b #0x0018, &0x0224 mov.b #0x0008, &0x0229 mov.b #0x0086, &0x022a mov.b #0x0018, &0x022c mov.b #0x0060, &0x0230 mov.b #0x0010, &0x0231 mov.b #0x0046, &0x0232 mov.b #0x0060, &0x0238 mov.b #0x0011, &0x0239 mov.b #0x0061, &0x023a mov.b #0x0040, &0x023b mov.b #0x0010, &0x0241 mov.b #0x0040, &0x0242 mov.b #0x0040, &0x0243 mov.b #0x0008, &0x0249 mov.b #0x0080, &0x024a mov.b #0x0006, &0x0251 ret

    ;seeding random universe of 20%

rdmsd mov #1,r15 mov #0x0200,r14 mov #6553,r13 sdlp cmp #128,r15 jeq asdlp push #0 ; space for result call #lcg32 pop r4 ; get result

    cmp r4,r13  ;20% comparison
    jge trsd
    jmp atrsd

trsd mov r4, 0(r14)

atrsd inc r14 inc r14 inc r15 jmp sdlp asdlp ret

; ; push (in this order) AnyWord to create space for return value on stack ; pop (in this order) Random word (between 1 and 32767) lcg32 push sr push r4 push r5 push &lcgseedh ; X(n-1)high word push &lcgseedl ; X(n-1)low word push #0x41c6 ; Ahigh constant for LCG from ISO C standards push #0x4e6d ; Alow constant call #mult32 incd sp ; remove unneeded leftover input word on stack incd sp ; acts like pop, but doesn't use a register push #0 ; Chigh constant for LCG from ISO C standards push #12345 ; Clow call #sra32 incd sp incd sp pop r4 pop r5 mov r4, &lcgseedh ; save X(n) as seed for next call to lcg32 mov r5, &lcgseedl and #0x7fff, r4 ; get bits 16-30 as random number output mov r4, 8(sp) ; and return on the stack pop r5 pop r4 pop sr ret

; push (in this order) A1h, A1l, B1h, B1l ; pop (in this order) null, null, R1h, R1l mult32 push sr push r4 push r5 push r6 push r7 push r8 push r9 push r10 push r11 mov 26(sp), r4 ; high word A mov 24(sp), r5 ; low word A mov 22(sp), r6 ; high word B mov 20(sp), r7 ; low word B clr r8 ; high word Result clr r9 ; low word Result ; start by handling Alow word mov #0x0001, R10 ; the mask mov #17, R11 ; loop counter, execute 16 times mult32lp1 dec R11 jeq mult32done1 bit R10, R5 jz mult32nxb1 push r6 ; add shifted B if corresponding bit of Alow was 1 push r7 push r8 push r9 call #sra32 pop r8 pop r8 pop r8 pop r9 mult32nxb1 rla r10 rla r7 rlc r6 jmp mult32lp1 ; now handle Ahigh word mult32done1 mov #0x001, R10 ; mask for high side mov #17, R11 ; loop counter for high side mult32lp2 dec R11 jeq mult32done2 bit R10, R4 jz mult32nxb2 push r6 ; add shifted B if corresponding bit of Ahigh was 1 push r7 push r8 push r9 call #sra32 pop r8 pop r8 pop r8 pop r9 mult32nxb2 rla r10 rla r7 rla r6 jmp mult32lp2 mult32done2 mov r8, 26(sp) mov r9, 24(sp) pop r11 pop r10 pop r9 pop r8 pop r7 pop r6 pop r5 pop r4 pop sr ret

; push (in this order) A1h, A1l, B1h, B1l ; pop (in this order) null, null, ResultH, ResultL sra32 push sr push r4 push r5 push r6 push r7 mov 18(sp), r4 ; high word A mov 16(sp), r5 ; low word A mov 14(sp), r6 ; high word B mov 12(sp), r7 ; low word B add R5, R7 addc R4, R6 mov R6, 16(sp) ; high word of answer mov R7, 18(sp) ; low word of answer pop r7 pop r6 pop r5 pop r4 pop sr ret

        .data

game .space 256 genk .word 0x0000,0x0000,0x0000,0x0000 genk1 .word 0x0000,0x0000,0x0000,0x0000 row0 .word 0x0000,0x0000,0x0000,0x0000 lcgseedh .word 0xa55a lcgseedl .word 0xa55a

/r/MSP430 Thread