; SOJ - zadanie c.3
; Martin Cernicka, kruzok 16
; sprievodna hudba: Wolfgang Amadeus Mozart

MODEL SMALL
JUMPS

CR	equ	0Ah, 0Dh
DLZKA	equ	254

DATA	SEGMENT
Prompt	DB	"Zadajte retazec: $"
Nic	DB	"Nezadali ste nic. Hm.", CR, "$"
Rovnake	DB	CR, "Text je rovnaky, ako jeho zrkadlovy obraz.", CR, "$"
Rozne	DB	CR, "Text a jeho zrkadlovy obraz sa lisia na pozicii "
Lisia	DB	"0000h.", CR, "$"

Text	DB	-1, DLZKA DUP (?)
Text2	DB	DLZKA DUP (?)
Kde	DW	?
DATA	ENDS

CODE	SEGMENT
ASSUME	CS:CODE, DS:DATA
start:	jmp	zacni

; skonvertuje cislo dlhe CL bajtov z DS:SI na text ES:DI
Hex2Str	proc near
	xor	CH, CH
	add	SI, CX
	dec	SI
HexLoop:std
	lodsb
	mov	AH, AL
	shr	AL, 1
	shr	AL, 1
	shr	AL, 1
	shr	AL, 1
	add	AL, 90h
	daa
	adc	AL, 40h
	daa
	cld
	stosb
	mov	AL, AH
	and	AL, 0Fh
	add	AL, 90h
	daa
	adc	AL, 40h
	daa
	stosb
	loop	HexLoop
	ret
Hex2Str	ENDP

zacni:	mov	AX, seg DATA
	mov	DS, AX
	mov	ES, AX

	mov	AH, 9			; vypis
	mov	DX, offset Prompt
	int	21h

	mov	AH, 0Ah			; nacitanie retazca
	mov	DX, offset Text
	int	21h

	mov	BL, [Text+1]		; ulozenie retazca opacne
	cmp	BL, 0			; bolo vobec nieco zadane?
	jne	dalej
	mov	AH, 9
	mov	DX, offset Nic
	int	21h
	mov	AX, 4CFFh
	int	21h

dalej:	mov	BH, 0
	mov	SI, offset Text+2
	mov	DI, offset Text2
	add	DI, BX
	mov	CX, BX
uloz:	cld
	lodsb
	std
	stosb
	loop	uloz

	mov	CX, BX			; porovnanie retazcov
	mov	SI, offset Text+2
	inc	DI
	cld
	repe	cmpsb

	cmp	CX, 0
	je	rovnaky

	sub	BX, CX
	mov	[Kde], BX

	mov	SI, offset Kde		; konverzia na text
	mov	DI, offset Lisia
	mov	CL, 2
	call	Hex2Str
	mov	AH, 9
	mov	DX, offset Rozne
	int	21h
	jmp	koniec

rovnaky:mov	AH, 9
	mov	DX, offset Rovnake
	int	21h

koniec:	mov	AX, 4C00h
	int	21h

CODE	ENDS
END	start

