Login Register






[FASM] Compare 2 strings filter_list
Author
Message
RE: [FASM] Compare 2 strings #4
(12-05-2016, 10:30 AM)Jochen Wrote:
Quote:I would just do:
Code:
mov ecx,cStr lea edx,[ecx+1h] next: mov al,[ecx] inc ecx test al,al jne next sub ecx,edx ; ecx = strlen

^ full manual approach using pointer arithmetic and comparing null-byte with test.

Essentially my approach was to load the address of the string into ecx, load the address of the string offset by 1 into edx (because of the last inc to ecx before the test), compare bytes from ecx register by moving them into lower eax (al) 8-bit segment, then subtract edx (string address + 1) from ecx to get the length. In the case of "", ecx is still incremented, which will match edx+1 to return 0.

Hi bitm0de: Your talking about getting the length of a string ?
                      For that i use this atm
Code:
proc ; strlen, strInput mov ecx,-1 mov al,0 mov edi,[strInput] cld repne scasb not ecx dec ecx ret endp; String length is in ECX

Ahh yeah. Correct. Change test to a cmp and increment an offset to another memory space for comparison. I don't know why I read this as Strlen rather than Compare... :S This would be the naive version of it though, the actual implementation of strlen() is not so simple, and involves a lot of bitwise arithmetic tricks: https://sourceware.org/git/?p=glibc.git;...8f68425dc2

My ASM is very small byte size though too.

You like using all of the special string instructions over doing things manually don't you?
(This post was last modified: 12-05-2016, 06:30 PM by bitm0de.)
- mostly braindead monkeys on this forum.

[+] 1 user Likes bitm0de's post
Reply





Messages In This Thread
[FASM] Compare 2 strings - by Jochen - 12-02-2016, 12:39 AM
RE: [FASM] Compare 2 strings - by bitm0de - 12-04-2016, 12:57 AM
RE: [FASM] Compare 2 strings - by Jochen - 12-05-2016, 10:30 AM
RE: [FASM] Compare 2 strings - by bitm0de - 12-05-2016, 06:28 PM
RE: [FASM] Compare 2 strings - by Jochen - 12-06-2016, 01:09 AM
RE: [FASM] Compare 2 strings - by bitm0de - 12-06-2016, 03:53 AM
RE: [FASM] Compare 2 strings - by Jochen - 12-06-2016, 06:14 AM