News:

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

LOCAL variables and the Stack

Started by Darrel, June 28, 2005, 01:40:50 PM

Previous topic - Next topic

Darrel

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

AeroASM

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.

hutch--

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.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

AeroASM

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]

Darrel

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

thomas_remkus

push hInstance
pop wc.hInstance

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

thomas