;80x86c.asm
;[LISTING THREE]

; Clears a buffer using MOV/ADD in a loop.
; Not a standalone program, but designed to be used with the Zen
; timer, as described in Listing 1.

	mov	dx,2		;repeat the test code twice, to make
				; sure it's in the cache (if there is one)
	mov	bx,dx		;distance from the start of one word
				; to the start of the next
	sub	ax,ax		;set buffer to zeroes
TestTwiceLoop:
	mov	cx,1024		;clear 1024 words starting at address
	mov	di,8000h	; DS:8000h (this is just unused memory
				; past the end of the program)
	call	ZTimerOn	;start timing (resets timer to 0)
StoreLoop:
	mov	[di],ax		;clear the current word
	add	di,bx		;point to the next word
	dec	cx		;count off words to clear until none
	jnz	StoreLoop	; remain
	call	ZTimerOff	;stop timing
	dec	dx		;count off passes through test code
	jz	StoreDone	;that was the second pass; we're done
	jmp	TestTwiceLoop	;that was first pass; do second pass with all 
                                ; instructions and data in the cache
StoreDone:

