The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: Darrel on June 28, 2005, 01:40:50 PM

Title: LOCAL variables and the Stack
Post by: Darrel on June 28, 2005, 01:40:50 PM
Hi all,

I'm having problems using a local variable as a displacement in a procedure.


SomeProc  PROC  dwWidth:DWORD,dwHeight:DWORD
    LOCAL    Something:DWORD
        .
        .
        .
        fstp    REAL4 PTR[edi+Something]
        .
        .
        .
        ret
SomeProc ENDP


I have checked the value of Something and it contains the correct value. If for a given situation I substitute 12 or ebx for Something it works fine. To be functional Something could vary over the course of execution. I'm in a multi-layered loop and all my registers are in use.

Any guidance would be appreciated.

Thanks for your time and consideration,

Darrel
Title: Re: LOCAL variables and the Stack
Post by: AeroASM on June 28, 2005, 03:00:07 PM
your local variable is accessed by [ebp+8]. Therefore your instruction gets translated by the preprocessor into

fstp real4 ptr [edi+[ebp+8]]


The above is not a valid x86 instruction.

Solution: put Something into a register.
Title: Re: LOCAL variables and the Stack
Post by: hutch-- on June 28, 2005, 03:04:34 PM
Darrel,

There are opcodes that allow a data section variable known at assembly time to be used both as the base address and as a displacement but it cannot be done with a stack variable.
Title: Re: LOCAL variables and the Stack
Post by: AeroASM on June 28, 2005, 04:26:01 PM
Are you sure? I don't think that any memory location can directly be used as a pointer, you must put it into a register first. Do you remember the discussion between:

mov eax,hInstance
mov eax,[hInstance]
Title: Re: LOCAL variables and the Stack
Post by: Darrel on June 28, 2005, 05:56:23 PM
Thanks for the replies,

I was planning on either putting the variable in the data section or moving it to a register. Just thought I'd check and see if I was missing something.

I do believe I have used a data section variable as an address displacement before.

Thanks again,

Darrel
Title: Re: LOCAL variables and the Stack
Post by: thomas_remkus on June 28, 2005, 06:34:31 PM
push hInstance
pop wc.hInstance

... how I remember well. Dirty little registers.

thomas