flat assembler
Message board for the users of flat assembler.

Index > Examples and Tutorials > CRC-32

Author
Thread Post new topic Reply to topic
Ali.Z



Joined: 08 Jan 2018
Posts: 361
Ali.Z
here is a stripped out version of my CRC-32, do not be confused with other CRC-32 variants; this is a plain CRC-32.

i tried to write some comments to clear out things, and used different names for labels and data to make it simper to read.

Code:
  include 'win32a.inc'
  format PE GUI 4.0

section '.text' code readable executable

    mov                 ebx,crc32_table ; base address
    xor                 ecx,ecx ; index used to update table entries
begin:
    mov                 eax,ecx
    and                 edx,0 ; inner loop counter
inner_loop:
    cmp                 dl,8
    jz                  update_table
    test                al,1 ; check for odd number
    jz                  shr_and_loop_back
    shr                 eax,1
    xor                 eax,0EDB88320h ; reversed (lil endian)
    inc                 dl
    jmp                 inner_loop
shr_and_loop_back:
    shr                 eax,1
    inc                 dl
    jmp                 inner_loop
update_table:
    mov                 [ebx+ecx*4],eax
    inc                 ecx
    or                  ch,ch
    jz                  begin
finish: ; as of here, we have full table ... the rest of the code is clear i think
    xor                 edx,edx
    and                 eax,edx
    not                 edx
    mov                 ecx,[input_length]
    mov                 esi,input_data
calc_crc32_checksum:
    lodsb
    xor                 al,dl
    movzx               edi,al
    mov                 eax,[ebx+edi*4]
    shr                 edx,8
    xor                 edx,eax
    loop                calc_crc32_checksum
    not                 edx
    push                10h
    push                crc32_checksum
    push                edx
    call                [itoa]
    add                 esp,0Ch
    push                0
    push                eax
    push                0
    push                0
    call                [MessageBox]
    sub                 eax,eax
    ret
    int3

section '.data' data readable writeable

  crc32_table rd 400h
  input_length dd 4
  input_data db 'fasm',0
  crc32_checksum rb 9


section '.idata' import data readable

  library user32,'user32.dll',\
          ntdll,'ntdll.dll'

  import user32,\
         MessageBox,'MessageBoxA'

  import ntdll,\
         itoa,'_itoa'

section '.reloc' fixups data readable discardable
    

_________________
Asm For Wise Humans
Post 10 Jul 2020, 00:39
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. Also on YouTube, Twitter.

Website powered by rwasa.