flat assembler
Message board for the users of flat assembler.

Index > Main > I need some clearence with regs EDX vs DL

Author
Thread Post new topic Reply to topic
Jay



Joined: 12 Aug 2014
Posts: 2
Jay
I was given of this piece of code, that should verify the checksum of a file, but i do not understand 1 thing, the mov of a byte in dl and the add operation of edx this code has sense if dl and edx were the same, but they are not! So, here the question. Is there some kind of relation between dl and edx ?

Code:
proc verifyChecksum stdcall, file_address:DWORD, file_size:DWORD

        pushad
        mov ebx,dword [file_address]
        mov eax,[ebx]
        add ebx,4
        mov ecx,[file_size]
        sub ecx,4
        ;checksum is in eax
        ;pointer to file in ebx
        ;size of file in ecx
        sub edi,edi
vs_calc_cs:
        sub edx,edx             ; zero edx reg
        mov dl,byte [ebx]       ; take 1 byte from the area pointed by ebx
        add edi,edx             ; add edi and edx
        inc ebx                 ; increment the address( ebx )
        dec ecx                 ; decrement the counter
        jnz vs_calc_cs          ; check if the last op return 0, if 0 EXIT_SUCCESS, if !0 cycle again
        ;calculated checksum is in edi
        cmp edi,eax
        jne vs_exit_error

vs_exit_success:
        popad
        mov eax,1
        ret

vs_exit_error:
        popad
        sub eax,eax
        ret

endp
    
Post 12 Aug 2014, 20:25
View user's profile Send private message Reply with quote
cod3b453



Joined: 25 Aug 2004
Posts: 619
cod3b453
Yes, dl is the 8 least significant bits of the (r/e)dx register (see http://sandpile.org/x86/gpr.htm for full view). The mixture of registers can be due to the limited permutations of encodable operations and/or the algorithm. Here the algorithm needs to carry up to 32bits in the add but the mov could have been movzx edx, byte [ebx].
Post 12 Aug 2014, 21:29
View user's profile Send private message Reply with quote
Jay



Joined: 12 Aug 2014
Posts: 2
Jay
ok, since dl represent the first byte of edx the sum with edi has sense. thx
Post 13 Aug 2014, 11:46
View user's profile Send private message Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1901
DOS386
Welcome to the FASM forum Smile

> if dl and edx were the same, but they are not!

ADD EDI,DL unfortunately doesn't work Sad

When you master primitive checksums, you might want to look at CRC32, MD5 and SHA256 Smile
Post 17 Aug 2014, 16:27
View user's profile Send private message Reply with quote
Foxxy



Joined: 14 Jul 2014
Posts: 42
Location: Somewhere over the rainbow...
Foxxy
DOS386 wrote:
Welcome to the FASM forum Smile

> if dl and edx were the same, but they are not!

ADD EDI,DL unfortunately doesn't work Sad

When you master primitive checksums, you might want to look at CRC32, MD5 and SHA256 Smile


I recently completed a CRC32 checksum utility written in assembly! Smile I was looking around the internet on how a SHA256 checksum works and the code behind it, any resources?
Post 27 Aug 2014, 20:54
View user's profile Send private message Reply with quote
shutdownall



Joined: 02 Apr 2010
Posts: 518
Location: Munich
shutdownall
Post 28 Aug 2014, 10:03
View user's profile Send private message Send e-mail Reply with quote
jhonny6721



Joined: 07 Aug 2014
Posts: 26
jhonny6721
You must avoid mix registers parts. In other words, you must avoid add a register that contains a 8 bit value with a 32 bit value. Because, only the value is stored in the first 8 bits. The rest of bits can have a wrong value.

By this reason, if you need to perform any operation with 8 bits or 16 bits part, you must set to zero the whole register.

Please, I´m sorry for my english. I am not a natice speaker
Post 01 Sep 2014, 19:35
View user's profile Send private message Reply with quote
shutdownall



Joined: 02 Apr 2010
Posts: 518
Location: Munich
shutdownall
Well mixing register is not that unusual.
XLAT for example but also MUL and DIV operate with different register sizes.
CBW, CWDE, MOVZX and MOVSX helps with loading 32 bit registers from 16 or 8 bit registers.
Post 01 Sep 2014, 21:41
View user's profile Send private message Send e-mail 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 GitHub, YouTube, Twitter.

Website powered by rwasa.