+mov di, GRID ; es:di -> GRID
+mov cx, COLS * ROWS ; for each cell
+
+.write_cell: ; do {
+ call xs ; [XSS] = rand
+ mov al, DEAD ; al = DEAD (likely)
+
+ test [XSS], 0b11
+
+ jnz .nz ; if ([XSS] % 4 == 0)
+ mov al, ALIVE ; al = ALIVE
+
+.nz:
+ stosb ; [es:(di++)] = al
+
+ loop .write_cell ; } while (--cx)
+
+ret
+
+; print_grid() - print GRID cells to screen -----------------------------------
+
+; (*) this function expects ds = 0 when called and sets es = 0 before
+; returning. this is simpler because in the rest of the program we want the
+; segment registers to be zeroed anyway.
+
+; clobbers ax, cx, di, si
+
+print_grid:
+
+mov ax, VGA >> 4