i got a dialog with an edit and an button

on the buttonclick i'm doing the following. It should take the string out of the edit and inc each char and put it back into the edit.
but it doesn't work :grin:

what am i doing wrong? :confused:



.data?
buffer db 512 dup(?)

.code
invoke GetWindowText,hwndEdit,ADDR buffer,512
mov esi,offset buffer ;copys offset of text in esi
.repeat
mov al, [esi] ;puts first byte in al and so on
inc al ;increments it
mov [esi], al ;puts it back in esi
inc esi ;goes so next char/byte in esi
.until (al==0) ;until the end is reached
dec esi ;the Zero at the end was also incremented
mov al, [esi] ;so it will be dec
dec al
mov [esi], al
mov offset buffer, esi ;this should put the offset in esi back to the buffer
;but it gives a error A2001: immediate operand not allowed
invoke SetWindowText,hwndEdit,addr buffer



greets Knighty
Posted on 2003-06-01 11:44:55 by Knighty
inc al means that al will never be 0. :)

Try


dec esi
@@:
inc esi
mov al,[esi]
or al,al
lea eax,[eax+1]
mov [esi],al
jnz @B
Posted on 2003-06-01 11:51:43 by roticv

mov offset buffer, esi ;this should put the offset in esi back to the buffer


This assembles to something like
mov immediate, reg

Which ofcourse will not work.

You should probably just do without that line, it seems kinda doomed anyway. You'd be overwriting your buffer with it anyway, which I'm guessing is not what you want.

Fake
Posted on 2003-06-01 11:52:38 by Fake51
@roticv

could you plz explain to me what lea eax, exactly does?

@Fake51

yeah you're right, it is kind of useless :)
Posted on 2003-06-01 14:31:44 by Knighty
Not only useless, it'll break your code ;) Removing it should make it work, given the changes roticv suggested, unless I'm mistaken.

The lea part is just the same as inc eax, if I'm not mistaken.

Fake
Posted on 2003-06-01 15:41:34 by Fake51
I changed it now to this


invoke GetWindowText,hwndEdit,ADDR buffer,512
mov esi,offset buffer
mov edi, esi ;saving the original offset
dec esi
@@:
inc esi
mov al,[esi]
or al,al
.IF (al!=0)
lea eax,[eax+1]
.ENDIF
mov [esi],al
jnz @B
invoke SetWindowText,hwndEdit,edi


and it works. :)

but why can't i just write inc al ? :stupid: :confused:

The lea part is just the same as inc eax, if I'm not mistaken.

yeah, when i change it to inc eax it does the same
Posted on 2003-06-01 19:17:59 by Knighty

@roticv

could you plz explain to me what lea eax, exactly does?


if im correct (im not 100% sure), that code is equivalent to this:

add eax,eax
inc eax

???

i remember reading abt that trick in the graphics programming black book a long time ago...so im not sure abt it
Posted on 2003-06-01 19:31:12 by AnotherWay83
lea eax, = inc eax
However it does not modify the zero flag. Thus I used it instead of inc eax as I do not want the zero flag to be modified. Anyway, it works the same if you change the test al,al/or al,al/cmp al,0 to cmp al,1 after the inc al.
Posted on 2003-06-01 20:35:48 by roticv
ah thx for your replies

now i understood it all :alright:
Posted on 2003-06-01 20:50:13 by Knighty
Looking into the code,


dec esi
@@:
mov al,[esi]
inc eax
mov [esi],al
inc esi
dec al
jnz @B
mov byte ptr [esi],al


Thus the new string will always be null-terminated.
Posted on 2003-06-02 03:23:59 by roticv