I have an array


arrScore dd 4*20 dup(?)

I treat it as a 2-dimension array
To insert a dword element to it:


...
mov EDI, arrScoreOffset
invoke atodw, ADDR szScore
mov DWORD PTR [EDI], EAX
add EDI, SIZEOF DWORD
; next element
; ...

arrScoreOffset is the address in the array to insert and is calculated before
szScore is an array of bytes (db) which is treated as a string and stores the number

To get an element:


mov ESI, arrScoreOffset
mov EAX, DWORD PTR [ESI]
mov score, EAX
add ESI, SIZEOF DWORD

score is a DWORD variable (used in a proc)

Are these codes correct ? It seems that the values are not stored correctly
Posted on 2003-09-27 10:01:58 by hcm2k3
That code seems ok, the only thing I can think of off hand is that arrScoreOffset is not the same value in both cases.
Posted on 2003-09-27 11:39:50 by Eóin
Have you tried:

mov ESI, OFFSET arrScoreOffset

Since arrScoreOffset is stored in your .data section you would want to point to that.. reading or writing..

If I'm wrong, don't shoot me.. i'm still learning too
Posted on 2003-09-27 11:41:03 by drarem
I am weary, but it seems correct to me. so what is wrong? Care to share the problem?
Posted on 2003-09-27 11:42:37 by roticv
Actually, this is an exercise from a book. I attach my source code here. I would appreciate if you take a look into it. Anyway, thanks for your reading !
You can read the description at the beginning of the file. Hope my comments are clear enough ;-)
I used WinASM to compile it. Just jumped to Win32ASM programming few weeks ago so there are a lot of problems. :-(
Posted on 2003-09-28 00:53:19 by hcm2k3
Remember: ESI, EDI and EBX are the registers you must preserve, not ECX!

Your CreateCombo proc uses ECX as the conditional for a while loop, but it also calls dwtoa(...) and SendMessage(...). These will almost definitly pollute ECX, and knacker your loop.

For further reference, you have at several points the following code:


dec <register>
cmp <register>, 0
jg somewhere

It is worth noting that dec will set the zero flag for you, so you do not need a second comparison.


dec <register>
jnz @B

Will work just as well, but is one instruction shorter.


In problems such as this, when they go wrong, it is worth pulling your functions out to check that they work individually. If you provide a test-bench where data is alread "read in from the file" you can check your parsing logic, without your "read from file" code being there to screw it up. Then when it comes to the point where you plug it all together, the only thing that can go wrong is the glue used to stick the function calls together.

Mirno
Posted on 2003-09-28 04:51:13 by Mirno
Thanks for your reply ! But what exactly do I have to modify my code ? I tried to make some changes in the CreateCombo proc but it didn't help !
Posted on 2003-09-28 05:42:39 by hcm2k3
The value of ecx will probably not be the same before and after a call to any windows API.

You need to use a variable to store the counter. This is really a simple task, and I don't think I should be telling you how to use locals...

Anyway, it'll feel like you've achieved something if you get the code to work all by yourself.

Mirno
Posted on 2003-09-28 09:25:26 by Mirno
Thanks ! I fixed these errors. Some procs such as dwtoa do change the content of registers after being called. This made my program crash.
Posted on 2003-09-29 11:13:08 by hcm2k3
The general rule is that when you code a function and when you make use of ebx, edi, esi you need to preserve them (ebp too, though people don't usually fool with it). The rest of the registers can be thrashed. So if you want your register (eax, edx, ecx) not to be molested, do preserve them.
Posted on 2003-09-29 11:33:17 by roticv