DATA	SEGMENT
STR	DB	'AAAAAAAAA1',13,10
STREND	LABEL	BYTE
FIZZ	DB	'Fizz',13,10
BUZZ	DB	'Buzz',13,10
BUZZEND	LABEL	BYTE
FIBU	DB	'FizzBuzz',13,10
FIBUEND	LABEL	BYTE
CNTHI	DW	1112H
BUF	DB	8192 DUP (?)
BUFEND1	LABEL	BYTE
	DB	16 DUP (?)
BUFEND2	LABEL	BYTE
DATA	ENDS

STACK	SEGMENT	STACK
	DB	512 DUP (?)
STACK	ENDS

CODE	SEGMENT
	ASSUME	CS:CODE,DS:DATA,ES:DATA,SS:STACK
START:
	MOV	AX,DATA
	MOV	DS,AX
	MOV	ES,AX
	MOV	DI,OFFSET BUF
	CLD
	MOV	BP,1111H
	MOV	CX,3
	MOV	DX,120FH
MAIN1:
	PUSH	CX
	DEC	DX
	JPE	NOTNUM
	CALL	WNUM
NEXT:
	POP	CX
	MOV	BX,OFFSET STREND - 3 + 1
NEXT1:
	DEC	BX
NEXT2:
	INC	BYTE PTR [BX]
	CMP	BYTE PTR [BX],'9'+1
	JB	MAIN1
	MOV	BYTE PTR [BX],'0'
	JE	NEXT1
	INC	CX
	JMP	NEXT2
NOTNUM:
	JE	FIZBUZ
	SHR	DH,1
	MOV	SI,OFFSET FIZZ
	MOV	CL,(OFFSET BUZZEND - OFFSET FIZZ) / 2
	JNC	FIZW
	ADD	SI,CX
FIZW:
	CALL	W
	JMP	NEXT
FIZBUZ:
	MOV	SI,OFFSET FIBU
	MOV	CL,OFFSET FIBUEND - OFFSET FIBU
	MOV	DX,120FH
	DEC	BP
	JNE	FIZW
	DEC	[CNTHI]
	JNE	FIZW
	CALL	FLUSH
	MOV	AX,4C00H
	INT	21H
WNUM:
	MOV	SI,OFFSET STREND
	SUB	SI,CX
W:
	REP	MOVSB
	CMP	DI,OFFSET BUFEND1
	JB	WRET
FLUSH:
	PUSH	DX
	MOV	DX,OFFSET BUF
	MOV	CX,DI
	SUB	CX,DX
	MOV	DI,DX
	MOV	BX,1
	MOV	AH,40H
	INT	21H
	POP	DX
WRET:
	RET
CODE	ENDS
	END	START
