Hi guys,
I have this routine in my code to check crc16 of a file:
mov cx, SIZE/2-1
mov bx, 0xffff
.l1:
mov ax, [es:si]
xor bx, ax
mov dl, 16
.l2:
shr bx, 1
jnc short .l3
xor bx, 0xa001
.l3:
dec dx
jnz short .l2
add si, 2
dec cx
jnz short .l1
and I have the file itself. I try to add crc, which is calculated automatically during compilation, to its end:
;. . . executable code and data
;. . .
;. . .
times SIZE-2-($-$$) db 0
;
; crc computation
;
crc = 0xffff
i = 0
while i < (SIZE/2 - 1)
load d word from (i)
crc = crc xor d
repeat 16
if crc & 1
crc = (crc shr 1) xor 0xa001
else
crc = crc shr 1
end if
end repeat
i = i + 2
end while
dw crc
But second piece of code doesn't work. It generates result as if "if crc & 1" always true, and "else" part is never executed. Why is it so? I already tried changing & to "and", tried "if (crc - (crc-1) = 0"... even tried WHILE directive instead of IF... but the result is always incorrect.
What am I doing wrong? Please, help