; Calculate Hamming distance...
; Algorithm by ewald and X-Calibre

.386
.Model Flat, StdCall

includelib	msvcrt.lib

printf	PROTO	C	:PTR BYTE, :VARARG

.data
input1	DWORD	1111111110b
input2	DWORD	0100111111b

output	BYTE	"Hamming distance: %u",0

.code
start:
	mov		eax, [input1]
	sub		ecx, ecx
	xor		eax, [input2]

@@loop:
	adc		ecx, 0
	add		eax, eax	; For small bitstrings, shr eax, 1 might be preferred, for it will lead to less iterations.
	jnz		@@loop

	adc		ecx, 0

	INVOKE	printf, ADDR output, ecx

	ret
END start
