flat assembler
Message board for the users of flat assembler.

Index > Main > [source]Simulate lstrlen

Author
Thread Post new topic Reply to topic
krackwar



Joined: 24 May 2008
Posts: 13
Location: Chile
krackwar
Code:
;This function simulate the lstrlen of windows and return in ecx
proc len,string
mov ebx,[string]
mov ecx,0h
.bucle:
inc ecx
cmp byte[ebx+ecx],0
JNE  .bucle
ret
endp         


Last edited by krackwar on 03 Sep 2008, 18:46; edited 1 time in total
Post 02 Sep 2008, 04:15
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
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.
Post 02 Sep 2008, 04:40
View user's profile Send private message Reply with quote
Garthower



Joined: 21 Apr 2006
Posts: 158
Location: Ukraine
Garthower
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
    
Post 02 Sep 2008, 08:44
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number Reply with quote
asmcoder



Joined: 02 Jun 2008
Posts: 784
asmcoder
[content deleted]


Last edited by asmcoder on 14 Aug 2009, 14:56; edited 3 times in total
Post 02 Sep 2008, 11:49
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
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.
Post 02 Sep 2008, 12:59
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4242
Location: 2018
edfed
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:

os construction:
boot
2nd boot
kernel
shell
files systems
fat12
file formats
memory manager
video manager
mouse & keyboard
dma
L1&2 caches
TSS
/TSS
...
..
.

or maybe, if i want it i can do it???
but no, if i need it it means i cannot do it : ( .
Post 02 Sep 2008, 17:48
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< 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 GitHub, YouTube, Twitter.

Website powered by rwasa.