Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

ASM Segmentation Fault

Name: Anonymous 2013-10-30 12:27

Hey /prog/rammers,

I try to do a comparison between two strings, but I get a Segmentation Fault, can you guys help me to find the problem ?
Here is the code : http://pastebin.com/Ji2VGH6N

Thank you in advance.

Name: Anonymous 2013-10-30 20:43

;; ...
add     edx, ecx ; d = d+s
fild    dword [edx]
;; ...


Your edx is 0 at that point (from the xor before the loop; unmodified during), and ecx is the loop counter/index. You're getting the memory at ecx, effectively. That's unlikely to be a good address. Same goes for the `fild dword [ecx]` after, too.

Name: Cudder !MhMRSATORI!fR8duoqGZdD/iE5 2013-10-31 10:34

Are you comparing two int* or char*? The C is for char, the code you wrote is for weirdly aligned ints.

Either way, that's way too many instructions...

pop edx
pop esi
pop edi
pop ecx
push ecx
repnz cmpsb  ; replace with cmpsd if you want to compare ints
pop eax
sub eax, ecx
push ecx
push eax
fild [esp]
pop eax
fild [esp]
pop eax
fdiv
jmp edx


(Untested. Written off-the-cuff.)

Name: Anonymous 2013-10-31 10:44

install gentoo

Name: Anonymous 2013-10-31 20:45

Why do you need floating point division to compare strings? x86 is a heaping pile of shit, but string comparison is at least one hoop you don't have to jump through. It has rep cmpsb and family, which is pretty convenient.

Name: Anonymous 2013-11-01 22:53

>>3,5
It's also slow shit to use that 'repXX cmpsb' microcode. You're better off comparing (len % 8), ie (len & 7) bytes first, then comparing the rest of the strings as 64-bit segments at a time.

Name: Cudder !MhMRSATORI!fR8duoqGZdD/iE5 2013-11-02 6:38

>>6
Not anymore (post-Netburst) it isn't. Nor was it pre-Netburst, if I remember correctly. It was only around those days when Intel jumped on the bloody RISC bandwagon. The latency is a bit higher but for large counts it outruns anything else (and ultimately gets limited by memory bandwidth).

Also, it's stupid to use something that's just a few times faster but TEN TIMES BIGGER... since this piece of code is unlikely to be the only bottleneck and you'll just end up creating more expensive cache misses and slow everything else down.

Name: Anonymous 2013-11-02 7:16

install gentoo

Name: Anonymous 2013-11-02 20:36

>>7
Only for stos and movs, scas and cmps are not particularly fast (Intel recommends against using them).
For Nehalem and greater the best way is to use pcmpistri.

Don't change these.
Name: Email:
Entire Thread Thread List