flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
LocoDelAssembly 02 Sep 2008, 04:40
Code: ;This function simulate the lstrlen of windows and return in ecx proc len, pString mov ecx, [pString] jmp .checkNull ; You may want "align 16" here .loop: inc ecx .checkNull: cmp byte [ecx], 0 jne .loop sub ecx, [pString] ret endp In your code you can safely remove "JE .termino" without changing procedure semantics. Note that your code has a bug, consider a string like " string db 0, 'GARBAGE', 0", your procedure will incorrectly report much more than zero. In some cases it could crash too because if there is no zero in the path before reaching a non-allocated memory region you'll get a page fault. |
|||
![]() |
|
Garthower 02 Sep 2008, 08:44
Here a fast x64 version of strlen. Without its special problems it's possible to alter easily on 32 bits.
Code: proc StrLenA ;ANSI PChar string in rcx. Length returns in rax ;str equ rcx mov rax,rcx lea rdx,[rax+7] mov r9,0101010101010101h mov r10,8080808080808080h mov r8,[rax] add rax,8 mov rcx,r8 sub rcx,r9 not r8 and rcx,r8 and rcx,r10 jnz .J1 .L1: mov r8,[rax] add rax,8 mov rcx,r8 sub rcx,r9 not r8 and rcx,r8 and rcx,r10 jz .L1 .J1: test ecx,80808080h jnz .L2 shr rcx,32 add rax,4 .L2: test rcx,8080h jnz .L3 shr rcx,16 add rax,2 .L3: shl cl,1 sbb rax,rdx ret endp |
|||
![]() |
|
asmcoder 02 Sep 2008, 11:49
[content deleted]
Last edited by asmcoder on 14 Aug 2009, 14:56; edited 3 times in total |
|||
![]() |
|
LocoDelAssembly 02 Sep 2008, 12:59
asmcoder, your code can't work even for a zero length string, it will crash with any input, check it. Additionally I don't understand why do you expect overflow.
BTW, this specific topic was discussed before, if someone founds the link please post it. |
|||
![]() |
|
edfed 02 Sep 2008, 17:48
http://board.flatassembler.net/topic.php?t=2628 ???
is it possible to limit the number of topics. make the fusion of many identical topics in only one. not about make it very fast, "all topics shall be compressed before november" for example. No, just: when we see this kind of remake, combine it with the previous one, and then, readers will see a lot of things for each subject. do it sometimes, not everydays, but do it... os construction can be limited to ~ 30 sub topics. only one page can show us the vast choice. Quote:
or maybe, if i want it i can do it??? but no, if i need it it means i cannot do it : ( . |
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.