flat assembler
Message board for the users of flat assembler.

Index > Main > Null termination?

Goto page Previous  1, 2, 3, 4
Author
Thread Post new topic Reply to topic
Madis731



Joined: 25 Sep 2003
Posts: 2140
Location: Estonia
Madis731
A long thread, but I thought I would through my 2 cents in.
1) If the null termination was a no-problem, then this thread wouldn't be so long Smile
2) Null termination is O(n) to scan, but knowing the length beforehand is just a lookup O(1).
3) Why would anyone need a better string library if the original one "isn't that bad"? http://bstring.sourceforge.net/
4) When I see that one goes to great lengths to optimize null-byte search, then is must be slow:
Code:
 #define has_nullbyte_(x) ((x - 0x01010101) & ~x & 0x80808080)

; OR the same in ASM:

mov edx, eax ;eax is the X from the C-style code
not eax
sub edx, 0x01010101
and eax, 0x80808080
and eax, edx
    
Post 31 Mar 2009, 10:13
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
Azu



Joined: 16 Dec 2008
Posts: 1159
Azu
Ugh now I'm having another problem.. Embarassed


If I make my code like
Code:
stdcall   [send],[g_hSock],edi+4,dword[edi],0    
It doesn't work (nothing is sent).

But
Code:
lea     eax,[edi+4]
stdcall  [send],[g_hSock],eax,dword[edi],0    
Works fine. Why? Confused
Post 31 Mar 2009, 19:46
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Because you have found a bug in the macro.

The way you should do that is this:
Code:
stdcall [send], [g_hSock], addr edi+4, dword[edi], 0
; OR
; invoke send, [g_hSock], addr edi+4, dword[edi], 0    


Your code, instead of generating an error was generating the following code
Code:
PUSH 0
PUSH DWORD [EDI]

; The next two pushes was generated by "edi+4"
PUSH EDI
PUSH 4

PUSH DWORD [g_hSock]
CALL DWORD [send]    
Post 31 Mar 2009, 20:02
View user's profile Send private message Reply with quote
Azu



Joined: 16 Dec 2008
Posts: 1159
Azu
Thanks.. I added the "addr".. but now it won't compile x_x
Post 31 Mar 2009, 20:15
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Ah, are you using win32{a|w}x.inc?

The "addr" will do nothing more than "lea edx, [parameter]/push edx" (so take care if you send EDX as parameter before any addr).

Take a look at http://flatassembler.net/docs.php?article=win32 (If hurried go straight to "2. Extended headers")
Post 31 Mar 2009, 20:55
View user's profile Send private message Reply with quote
Azu



Joined: 16 Dec 2008
Posts: 1159
Azu
Working fine now. Thanks. Smile
Post 01 Apr 2009, 04:37
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
Madis731



Joined: 25 Sep 2003
Posts: 2140
Location: Estonia
Madis731
Code:
        ;xmm0 is loaded with 16 bytes of comparable string
        pxor     xmm1,xmm1
        pcmpeqb  xmm0,xmm1
        pmovmskb eax,xmm0
        ;eax = will show a bit for each byte position
        ;      0 means that no nullbyte found
    

_________________
My updated idol Very Happy http://www.agner.org/optimize/
Post 01 Apr 2009, 09:01
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page Previous  1, 2, 3, 4

< 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.