RE: [FASM] Compare 2 strings 12-05-2016, 06:28 PM
#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.



![[+]](https://sinister.li/images/modern/collapse_collapsed.png)