;
; *** Listing 8-13 ***
;
; Adds together bytes from two arrays, subtracts a byte from
; another array from the sum, and stores the result in a fourth
; array, for all elements in the arrays.
; Uses the mod-reg-rm form of XCHG.
;
	jmp	Skip
;
ARRAY_LENGTH	equ	1000
Array1	db	ARRAY_LENGTH dup (3)
Array2	db	ARRAY_LENGTH dup (2)
Array3	db	ARRAY_LENGTH dup (1)
Array4	db	ARRAY_LENGTH dup (?)
;
Skip:
	mov	dx,offset Array1
	mov	bx,offset Array2
	mov	si,offset Array3
	mov	di,offset Array4
	mov	cx,ARRAY_LENGTH
	call	ZTimerOn
ProcessingLoop:
	xchg	dx,bx		;point BX to Array1,
				; point DX to Array2
	mov	al,[bx]		;get next byte from Array1
	xchg	dx,bx		;point BX to Array2,
				; point DX to Array1
	add	al,[bx]		;add Array2 element to Array1
	sub	al,[si]		;subtract Array3 element
	mov	[di],al		;store result in Array4
	inc	dx		;point to next element of each array
	inc	bx		
	inc	si		
	inc	di
	loop	ProcessingLoop	;do the next element
	call	ZTimerOff
