flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > compute CRC of a file at assembly time using directives

Author
Thread Post new topic Reply to topic
zhak



Joined: 12 Apr 2005
Posts: 490
Location: Belarus
zhak
Hi guys,
I have this routine in my code to check crc16 of a file:
Code:
    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:
Code:
;. . . 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
Post 20 Aug 2012, 23:06
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17084
Location: In your JS exploiting you and your system
revolution
"&" is a logical comparator. Instead, use the binary operator "and".
Post 20 Aug 2012, 23:16
View user's profile Send private message Visit poster's website Reply with quote
zhak



Joined: 12 Apr 2005
Posts: 490
Location: Belarus
zhak
changed & to "and". and also found an error in the cycle. changed "while i < (SIZE/2 - 1)" to "repeat RLDR_SIZE/2 - 1". now works! thanks! truth, that morning is much better than deep night. you don't see obvious things sometimes at night...
Post 21 Aug 2012, 08:14
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.