TITLE	Assignment 1 ASSIGNMENT1.ASM

COMMENT | Written by Caitlin Ross, 100735219, COMP 2003 A 
	|

.MODEL SMALL
.STACK 100H

.DATA

	char_prompt	DB 'Please enter a character: ', 0
	output_msg	DB 'The Hamming distance between the two characters is ', 0
	continue_prompt	DB 'Do you want to continue? (y/n) ', 0
	char1		DB ?
	char2		DB ?
	response	DB ?
	arraych1	DB 8 dup (00H)
	arraych2	DB 8 dup (00H) 
	counter		DW ?

.CODE

INCLUDE io.mac
.486 

main PROC
	.STARTUP

start_program:				;(line 29)
	nwln
	PutStr char_prompt		;Prompt user for a character
	mov AH, 01H			;Get character from keyboard
	int 21H
	mov char1, AL			;Move the character into char1

	nwln
	PutStr char_prompt		;Prompt user for another character
	mov AH, 01H			;Get character from keyboard
	int 21H
	mov char2, AL			;Move the character into char2

	mov CX, 0
	mov BX, OFFSET arraych1
	mov SI, OFFSET arraych2

start_init_loop:			;(line 46)
	mov byte ptr [BX], 00H		;Initialize arraych1 to zero
	mov byte ptr [SI], 00H		;Initialize arraych2 to zero

	inc BX				;Go to next element in arraych1
	inc SI				;Go to next element in arraych2
	inc CX				;Increment loop counter
	cmp CX, 8			;If CX<8, keep going in loop
	jne start_init_loop

end_init_loop:				;(line 56)
	mov AX, 01H			;Use AX for the mask
	mov BX, OFFSET arraych1		;Use BX to access arraych1
	mov SI, OFFSET arraych2		;Use SI to access arraych2
	mov CX, 0			;Set CX to 0 to use as loop counter

start_array_loop:			;(line 62)
	mov DH, 0H
	mov DL, char1
	and DX, AX			;if((char1 & mask) != 0)
	cmp DX, 00H
	je end_if_1
	mov byte ptr [BX], 01H		;arraych1[CX] = 1

end_if_1:				;(line 70)
	mov DH, 0H
	mov DL, char2
	and DX, AX			;if((char2 & mask) != 0)
	cmp DX, 00H
	je end_if_2
	mov byte ptr [SI], 01H		;arraych2[CX] = 1

end_if_2:				;(line 78)
	inc BX				;Go to next element in arraych1
	inc SI				;Go to next element in arraych2
	shl AX, 1			;Shift mask to next position
	inc CX				;Increment loop counter
	cmp CX, 8			;If CX<8, keep going in loop
	jne start_array_loop

end_array_loop:				;(line 86)
	mov counter, 0			;Set the counter to 0
	mov CX, 0			;Use CX as the loop counter
	mov BX, OFFSET arraych1		;Use BX to access arraych1
	mov SI, OFFSET arraych2		;Use SI to access arraych2

start_hamming_loop:			;(line 92)
	mov AH, 00H
	mov AL, [BX]
	mov DH, 00H
	mov DL, [SI]
	cmp DX, AX			;if(arraych1[CX] == arraych2[CX])
	je end_hamming_if
	inc counter

end_hamming_if:				;(line 101)
	inc BX				;Go to next element in arraych1
	inc SI				;Go to next element in arraych2
	inc CX				;Increment loop counter
	cmp CX, 8			;If CX<8, keep going in loop
	jne start_hamming_loop

end_hamming_loop:			;(line 108)
	nwln
	PutStr output_msg		;Display the output message
	PutInt counter			;Display the hamming distance
	nwln
	PutStr continue_prompt		;Ask user whether to continue
	GetCh response			;Read in the user's response

	cmp response, 'n'		;Check answer (lower case)
	je end_program
	cmp response, 'N'		;Check answer (upper case)
	je end_program
	jmp start_program		;If (answer != 'n' or 'N'), start program again
end_program:				;(line 121)

	.EXIT
main ENDP

END main