Task

Create a Thue-Morse sequence.



See also
   YouTube entry: The Fairest Sharing Sequence Ever
   YouTube entry: Math and OCD - My story with the Thue-Morse sequence
   Task: Fairshare between two and more


	org	100h
	;;;	Write 256 bytes of ASCII '0' starting at address 200h
	lxi	h,200h	; The array is page-aligned so L starts at 0
	mvi	a,'0'	; ASCII 0
zero:	mov	m,a	; Write it to memory at address HL
	inr	l	; Increment low byte of pointer, 
	jnz	zero	; until it wraps to zero.
	;;;	Generate the first 256 elements of the Thue-Morse sequence.
gen:	jpe	$+4	; If parity is even, skip next instruction
	inr	m	; (If parity is odd,) increment byte at HL (0->1) 
	inr	l	; Increment low byte of pointer (and set parity),
	jnz	gen	; Until it wraps again. 
	;;;	Output using CP/M call
	inr	h	; Increment high byte,
	mvi	m,'$'	; and write the CP/M string terminator there.
	mvi	c,9	; Syscall 9 = print string
	lxi	d,200h	; The string is at 200h
	jmp	5