News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Scale index error.

Started by Farabi, April 07, 2005, 11:38:15 AM

Previous topic - Next topic

Farabi

Im playing with memory on windows. Im just creating a tiny block of memory allocation. When I use the index like this [edx+ecx*4] the program suddenly stop responding and I need to use window task manager to shut it down. I have checked it muliple time to make sure that was not my fault but the assembler did. Any idea how to make it runs normal?
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

hutch--

I am moving this topic to the workshop as it will be read by more people. The MASM32 subforum is fo4r direct MASM32 project issues.

The notation,


[edx+ecx*4]


Is normal assembler notation so it will be a mistake in your code design, the notation directly translates to an opcode in the processor so its not the problem. Just make sure you understand the compex addressing modes in x86 hardware,

[eax+ebx*4+16]

eax = base address
ebx = index
*4 = scale
+16 = displacement
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

roticv

Quote from: Farabi on April 07, 2005, 11:38:15 AM
Im playing with memory on windows. Im just creating a tiny block of memory allocation. When I use the index like this [edx+ecx*4] the program suddenly stop responding and I need to use window task manager to shut it down. I have checked it muliple time to make sure that was not my fault but the assembler did. Any idea how to make it runs normal?
Seriously if you are using masm, the encoding for the instruction is correct. Post your code as I suspect it is really your mistake (forgot to handle some exception etc)

thomasantony

Hi,
This format is usually used when you have a table of addresses or offsets to some strings or something. So if edx is the OFFSET of the table of offsets :P and ecx is the index into it to get an string or whatever at the address pointed by that index you use [edx+ecx*4]. Hope I made myself clear. Will post an example tomorrow! :U

Thomas :U
There are 10 types of people in the world. Those who understand binary and those who don't.


Programmer's Directory. Submit for free

Tedd

A purely random guess, but are you trashing the contents of either/both of those registers before trying to use them?
Any calls to functions in between getting their values and using them will mess them up. Push-pop :toothy
No snowflake in an avalanche feels responsible.

thomasantony

Quote from: Tedd on April 08, 2005, 11:20:23 AM
A purely random guess, but are you trashing the contents of either/both of those registers before trying to use them?
Any calls to functions in between getting their values and using them will mess them up. Push-pop :toothy
Here's a way around that. Use ebx instead of ecx. All the API functions preserve those.(esi edi ebx) . You only have to preserve them in your own functions too.

Thomas :U
There are 10 types of people in the world. Those who understand binary and those who don't.


Programmer's Directory. Submit for free

Farabi

Okay, thanks. Im not use any local variable, but I use edi as the temporary memory. I have found the mistake, yes it was my mistake. Something is use the edx register and I forgot not use push-pop.

Here is the source, i put it in here.

http://www.masmforum.com/simple/index.php?topic=1218.0
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"