;80x86b.asm
;[LISTING TWO]

; Copies one string to another string, converting all characters to
; uppercase in the process, using no string instructions.
; Not a standalone program, but designed to be used with the Zen
; timer, as described in Listing 1.

	jmp	Skip		;skip over data in CS and subroutine

SourceString	label	word		;sample string to copy
	db	'This space intentionally left not blank',0
DestString	db	100 dup (?)	;destination for copy

; Copies one zero-terminated string to another string,
; converting all characters to uppercase. 
; Input: DS:SI = start of source string; DS:DI = start of destination string
; Output: none
; Registers altered: AL, BX, SI, DI

CopyStringUpper:
	mov	bl,'a'	;set up for fast register-register
	mov	bh,'z'	; comparisons
StringUpperLoop:
	mov	al,[si]	;get the next character and
	inc	si	; point to the following character
	cmp	al,bl	;below 'a'?
	jb	IsUpper	;yes, not lowercase
	cmp	al,bh	;above 'z'?
	ja	IsUpper	;yes, not lowercase
	and	al,not 20h ;is lowercase-make uppercase
IsUpper:
	mov	[di],al	;put the character into the new string and
	inc	di	; point to the following location
	and	al,al	;is this the zero that marks the end of the string?
	jnz	StringUpperLoop ;no, do the next character
	ret

; Calls CopyStringUpper to copy & convert SourceString->DestString.
Skip:
	call	ZTimerOn
	mov	si,offset SourceString	;point SI to the string to copy from
	mov	di,offset DestString	;point DI to the string to copy to
	call	CopyStringUpper		;copy & convert to uppercase
	call	ZTimerOff

