Hi there,

I recently started coding again in Win32ASM (had to pause that due to school, we do ANSI C *yack*) so I run over some mistakes :(



; ########################################
ReadWord PROC uses EAX ECX ESI EDI EBX EDX lnnumber:DWORD

CLD
XOR EAX,EAX
XOR ESI,ESI
XOR EDI,EDI
MOV EBX,lnnumber
MOV ESI,pMemory

.WHILE EBX>0
MOV AL,byte ptr [ESI]
CMP AL,13
JNZ @F
DEC EBX
INC ESI
@@:
INC ESI
.ENDW
XOR ECX,ECX

@@:
MOV AL,byte ptr [ESI]
CMP AL,13
JE _ready
MOV byte ptr buffer[ECX],AL
INC ECX
INC ESI
JMP @B

_ready:
ret

ReadWord ENDP

; ########################################

BreakLine PROC uses EAX EBX ECX ESI EDI EBX EDX InputString:DWORD

XOR EAX,EAX
XOR EBX,EBX
XOR ECX,ECX
XOR ESI,ESI
MOV CurrentSegment,1
mov FoundFlag,0
MOV ESI,InputString

the_break_loop:

MOV AL,byte ptr [ESI]
CMP AL,13h
JE leave_it
CMP AL,20h
JE break_it

.IF CurrentSegment == 1
MOV byte ptr buffer1[ECX],AL
.ELSEIF CurrentSegment == 2
MOV byte ptr buffer2[ECX],AL
.ELSEIF CurrentSegment == 3
MOV byte ptr buffer3[ECX],AL
.ELSEIF CurrentSegment == 4
MOV byte ptr buffer4[ECX],AL
.ELSEIF CurrentSegment == 5
MOV byte ptr buffer5[ECX],AL
.ELSE
JMP leave_it
.ENDIF

INC ECX
INC ESI
JMP the_break_loop

break_it:
inc CurrentSegment
XOR ECX,ECX
INC ESI
JMP the_break_loop

leave_it:
INC ECX
INC ESI
XOR EAX,EAX
XOR EBX,EBX
XOR ECX,ECX
XOR ESI,ESI

ret

BreakLine ENDP

; ########################################


I open a text file (plain ASCII), break it into single lines (the first function) and then use the second function to break this line into single buffers.
This is by far not the best method but it worked for me till now.

However, while reading in the file I get no error but just a program termination.

Original File:


0003 00 106FED4989DF738B12 06EC FFFE <- w/o a space at the end
0004 10 06D9572CD78810E4AA 06EC ---- <- w/o a space at the end

Modified File:


83B1 00 02D639D15C80222858 06EC 0190 <- with a space at the end
83B1 10 040DC7A120A3A503D5 06EC ---- <- with a space at the end


On the original file the program doesn't work.
With the modified file it just runs as it should.

Problem is, that the file contains several thousand lines, so adding a space at every line is not acceptable :)

Can anybody tell me, how stupid I am?

Greets YaWNS aka Stefan K.
Posted on 2002-07-01 15:19:59 by YaWNS
Questions:

Do you want the CR to be stored in buffer?
With the published code, it's not.


@@:
MOV AL,byte ptr [ESI]
CMP AL,13
JE _ready
MOV byte ptr buffer[ECX],AL ; <-- will not store CR at end
INC ECX
INC ESI
JMP @B


Hmmm. 13h is not the same as 13. Is that in your code?


MOV AL,byte ptr [ESI]
CMP AL,13h
JE leave_it
CMP AL,20h
JE break_it
Posted on 2002-07-01 17:42:41 by tenkey
tenkey is right,
13h and 20h are incorrect :)
Posted on 2002-07-01 19:08:51 by bazik
This is really weird...

changing it to 13 and 20 it crashes. :)
changing them to 0Dh and 20h works with the modified one.
changing them to 0Dh and 32 works with the modified one.

None of these works with the original :(

I really don't know what is wrong here.

As for the CR, no I don't want it since the item gets stored in a listview.

Greets YaWNS
Posted on 2002-07-02 00:00:48 by YaWNS
Debugging always helps...
Posted on 2002-07-02 10:36:45 by comrade
I don't know if this is a problem either.
The proc ReadWord doesn't store a CR, but the BreakLine proc expects to see one.
Posted on 2002-07-02 14:46:16 by tenkey
Uhh is this like separating word by word from a buffer?? Could you elaborate more on what are you suppose to do?

The only thing I can see this being solve is to rewrite the whole thing from the start. Because the code is already a mess and it's breaking on different situations.
Posted on 2002-07-02 15:20:24 by stryker

Uhh is this like separating word by word from a buffer?? Could you elaborate more on what are you suppose to do?

The only thing I can see this being solve is to rewrite the whole thing from the start. Because the code is already a mess and it's breaking on different situations.


Part 1: Yes, exactly. I never had problems with it before, so I don't know why this occurs now.
All I want to do at the moment is read the contents line by line, and split the line up into some strings which then go into a listview.

Part 2: I feared this reply as I don't have any time left at the moment to redo the whole function. No, this is no request to anybody doing it for me, even though it might sound like that.
What really distgusts me, is the fact, that I am able to read the file completely in ANSI C but not in my favourite programming language.
But I see your point, stryker. This function has been patches several times so at any time it was sure I had to redo it. :(

Greets YaWNS
Posted on 2002-07-02 16:04:32 by YaWNS
Oh I see your point ;) I think I have the same proggy, I'll check my HD since I already forgot the filename. :alright:
Posted on 2002-07-02 16:19:26 by stryker
Here's the proggy I made, I hope this will help :)
Posted on 2002-07-02 18:06:16 by stryker
please change the Tokenize procedure to this:
[size=9]strtok PROC USES ebx esi edi hWnd:DWORD, lpszBuffer:DWORD, lpTokenBuffer:DWORD


mov esi, lpszBuffer
mov edi, lpTokenBuffer

__START_TOKENIZER:

xor ebx, ebx
xor ecx, ecx

__SCAN:

mov dl, BYTE PTR [esi+ecx]
or dl, dl
jz __EXIT_SCAN
cmp dl, 20h
je __RESET_AND_PRINT
cmp dl, 0Dh
je __RESET_AND_PRINT
cmp dl, 0Ah
je __RESET_AND_PRINT
cmp dl, 9h
je __RESET_AND_PRINT

mov BYTE PTR [edi+ebx], dl
inc ebx
jmp __SCAN_FINISHED

__RESET_AND_PRINT:

cmp BYTE PTR [edi], 0
je __SCAN_FINISHED

mov BYTE PTR [edi+ebx], 0

push ecx
mov eax, hWnd
xcall SendMessage, eax, LB_ADDSTRING, NULL, edi
pop ecx

xor ebx, ebx
mov BYTE PTR [edi], bl

__SCAN_FINISHED:

inc ecx
jmp __SCAN

__EXIT_SCAN:

mov BYTE PTR [edi+ebx], 0

mov eax, hWnd
xcall SendMessage, eax, LB_ADDSTRING, NULL, edi

ret

strtok ENDP[/size]
This is much more friendlier style.

hWnd - handle to a window, customize the strtok procedure to suit your need
lpszBuffer - pointer to a null terminated source buffer.
lpTokenBuffer - pointer to the token buffer, the maximum token string size will depend on the size of this buffer.
[size=9]from the main source file of the program above ... instead of


xcall token

replace it with

xcall strtok, eax, ecx, OFFSET g_Token[/size]
Have Fun!!!
Posted on 2002-07-02 19:48:51 by stryker