DATA	SEGMENT
STR	DB	'AAAAAAAAA1',13,10
STREND	LABEL	BYTE
	DB	'FizzBuzz',13,10
FIBUEND	LABEL	BYTE
FIZZ	DB	'Fizz',13,10
BUZZ	DB	'Buzz',13,10
BUZZEND	LABEL	BYTE
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	BX,1112H
	MOV	CX,3
MAIN2:
	MOV	DX,120FH
MAIN1:
	DEC	DX
	JS	MAIN2
	PUSH	CX
	MOV	SI,OFFSET STREND
	JPO	NEXTM
	JE	FIZBUZ
	SHR	DH,1
	MOV	SI,OFFSET FIZZ + (OFFSET BUZZEND - OFFSET FIZZ) / 2
	MOV	CL,(OFFSET BUZZEND - OFFSET FIZZ) / 2
	JC	NEXT
NEXTM:
	SUB	SI,CX
NEXT:
	REP	MOVSB
	CMP	DI,OFFSET BUFEND1
	JB	NOFLS
FLUSH:
	PUSH	BX
	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
	POP	BX
NOFLS:
	POP	CX
	JCXZ	ENDPRG
	MOV	SI,OFFSET STREND - 3 + 1
NEXT1:
	DEC	SI
NEXT2:
	INC	BYTE PTR [SI]
	CMP	BYTE PTR [SI],'9'+1
	JB	MAIN1
	MOV	BYTE PTR [SI],'0'
	JE	NEXT1
	INC	CX
	JMP	NEXT2
FIZBUZ:
	MOV	CL,OFFSET FIBUEND - OFFSET STREND
	DEC	BP
	JNE	NEXT
	DEC	BX
	JNE	NEXT
	PUSH	BX
	JMP	FLUSH
ENDPRG:
	MOV	AX,4C00H
	INT	21H
CODE	ENDS
	END	START
