flat assembler
Message board for the users of flat assembler.

Index > Main > scasD Instruction

Author
Thread Post new topic Reply to topic
Everhest



Joined: 26 Jun 2008
Posts: 84
Location: Russia
Everhest
Hi, how using this instruction? Im write function:
Code:
proc GetHeaderLenght Header
        cld
        mov     edi, [Header]
        mov     ecx, 4096
        mov     eax, 0D0A0D0Ah
        repne   scasd
        mov     eax, edi
        sub     eax, [Header]
        ret
endp             
    

but return value not a valid... This function processes buffer from HEAD request (sockets). Function must find <db 13, 10, 13, 10> in the buffer and returned size of socket.header...

please help...

_________________
Forgive for my bad english, I from russia...
Post 12 Jun 2009, 17:54
View user's profile Send private message ICQ Number Reply with quote
Mac2004



Joined: 15 Dec 2003
Posts: 313
Mac2004
Everhest: Areyou setting ES segment register properly before using scasd?
This is first thing that comes into my mind.

Regards,
Mac2004
Post 12 Jun 2009, 18:18
View user's profile Send private message Reply with quote
Everhest



Joined: 26 Jun 2008
Posts: 84
Location: Russia
Everhest
o_0 Why?
Post 12 Jun 2009, 18:22
View user's profile Send private message ICQ Number Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
It won't work because it is requiring the <13, 10, 13, 10> sequence to be located at dword boundaries (i.e., EDI is incremented by 4 each time instead of 1). repne scasd is useful for dword arrays, but for searching patterns in strings it is not.

A possible solution (untested) would be the following:
Code:
proc GetHeaderLenght Header
        cld
        mov     edi, [Header]
        mov     ecx, 4096
        mov     eax, 0A0D0A0Dh ; This is the correct number to search for the <$0d, $0a, $0d, $0a> pattern

.find$0D:
        repne   scasb

        cmp     ecx, 3
        jb      .notFound

        cmp     [edi-1], eax
        jne     .find$0D

        add     edi, 3

.exit:
        mov     eax, edi
        sub     eax, [Header]

        ret

.notFound:
        lea     edi, [edi+ecx]
        jmp     .exit
endp    
Post 12 Jun 2009, 18:30
View user's profile Send private message Reply with quote
Mac2004



Joined: 15 Dec 2003
Posts: 313
Mac2004
eg.
Code:
mov eax, ES_SELECTOR
mov es, eax 
    



Using edi is actually using es:edi register pair and thus es register needs to be set properly.

This link may help you a bit?

http://faydoc.tripod.com/cpu/scasd.htm

Regards
Mac2004
Post 12 Jun 2009, 19:09
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Mac2004, it should be AX instead of EAX but yet I don't think that he is experiencing that problem too as 32-bit OSes not satisfying DS=ES=SS are rare (if there is really any).

Also, since he is using the proc macro, it is very likely he is using Windows, so, ES should be already set correctly (unless it was explicitly changed by him somewhere).

[edit] By DS=ES=SS I mean the memory space those segments are allowing to access. Typically all of them four allow to access the entire 4 GB address space (i.e., "mov eax, [seg:edi]" should produce the same result no matter which one of the four seg you choose).[/edit]

[edit2] Where I've said "four" it is "three"[/edit]


Last edited by LocoDelAssembly on 13 Jun 2009, 04:54; edited 1 time in total
Post 12 Jun 2009, 19:34
View user's profile Send private message Reply with quote
Mac2004



Joined: 15 Dec 2003
Posts: 313
Mac2004
Loco: I guess I'am so much used to 'assuming nothing' due to fact that I do my programming under plain protected mode.
So there's no OS to do anything for me..
Post 13 Jun 2009, 04:22
View user's profile Send private message Reply with quote
Everhest



Joined: 26 Jun 2008
Posts: 84
Location: Russia
Everhest
People BIG thank you...
Post 13 Jun 2009, 06:19
View user's profile Send private message ICQ Number Reply with quote
Mac2004



Joined: 15 Dec 2003
Posts: 313
Mac2004
Everhest: I guess you managed to solve the problem. That's good Smile

Regards,
Mac2004
Post 13 Jun 2009, 07:09
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.