Hello everybody. I need to find the longest sentence in a string, for example "Abc. Abcd. Abcde". Does anyone have any idea how to do this?
Yes, several.
Post the code you have so far, we don't do homework assignments.
:lol nice 1 clive I nearly got suckered into that one
EDIT: I wrote the proc if you have a good start :lol
.data
szTest db "Abc. Abcd. Abcde",0
.code
lea esi,szTest
movzx eax,BYTE ptr [esi]
mov ebx,esi
mov edi,esi
xor edx,edx
xor ecx,ecx
.while 1
lea esi,[esi+1]
.if eax == '.' || !eax
.if edx > ecx
mov ecx,edx
mov edi,ebx
.endif
xor edx,edx
mov ebx,esi
.break .if !eax
.else
lea edx,[edx+1]
.endif
movzx eax,BYTE ptr [esi]
.endw
; edi = pointer to largest sentence
; ecx = size of sentence
:lol
if he hands that in, qWord, his instructor will know she(he?) didn't write it :P
i am confused. why lea esi, [esi+1], is it faster ?
edit: Thinking about it, it actually makes more sense than an add.
Plus it can be really useful if you don't want to effect the flags, especially the carry ie lea esi,[esi+4].
inc esi might be better
if the step were more than one, i might use lea
inc does affect the flags - but always leaves the carry flag unchanged
inc reg32 is a single byte instruction - this can make the overall loop smaller - which is the real advantage
Quote from: dedndave on May 20, 2010, 03:03:25 PM
if he hands that in, qWord, his instructor will know she(he?) didn't write it :P
what would his instructor then said to this this (obfuscated) code ? :cheekygreen::
lea esi,szTest
movzx eax,BYTE ptr [esi]
mov ebx,esi
mov edi,esi
xor edx,edx
xor ecx,ecx
xor ebp,ebp
.while 1
lea esi,[esi+1]
xor eax,0ffffffd1h
add eax,1
adc ebp,0
xor eax,02dh
add eax,1
adc ebp,0
mov ebp,0
lea edx,[edx+1]
cmovnp edx,ebp
cmovnp ebx,esi
cmp edx,ecx
cmova ecx,edx
cmova edi,ebx
test eax,eax
.break .if ZERO?
movzx eax,BYTE ptr [esi]
.endw
; edi = pointer to largest sentence
; ecx = size of sentence
qword