News:

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

can not get local variable address

Started by Emil_halim, November 17, 2010, 02:45:29 PM

Previous topic - Next topic

Emil_halim

hi all

i have a local variable and want to get it's address by & symbol, but it did not compiled.

program localpointer;

#include("macros/macros.hhf")
   
var
   m : uns32;   
       
begin localpointer;
         
   mov(&m,esi);
         
end localpointer;


dedndave


Emil_halim


yes i know lea but i do not mean by this way , why hla refuse to compile and take the address be lea automatically?

Sevag.K

the '&' operator is computed at compile/link time for static objects.  for run time address, you need lea.


Emil_halim

ok ,

i am thinking to create a macro that have the same name of mov instruction. and in the macro we can check if the parameter is a memory
(using @ismem) and if it is non-static objects we emit lea instead of mov.

something like this


#id( mov ) 

#macro mov( a , b);
     #if(@ismem(a)) then
          is non-static objects
          LEA(a,b);
     #else
          mov(a,b);
     #endif
#endmacro;

Emil_halim


is there a way to know if the parameter of a macro is a local variable or not ?

Sevag.K

HLA Reference Manual 5/24/10 Chapter 13
Public Domain Created by Randy Hyde Page 274

@class( identifier_or_expression )
This returns a symbol's class type. The class type is constant, value, variable, static, etc., this
has little to do with the class abstract data type See the "hla.hhf" header file for the current symbol
class definitions. At the time this was written, the definitions were:
hla.cIllegal:= 0;
hla.cConstant:= 1;
hla.cValue:= 2;
hla.cType := 3;
hla.cVar := 4;
hla.cParm := 5;
hla.cStatic:= 6;
hla.cLabel:= 7;
hla.cProc := 8;
hla.cIterator:= 9;
hla.cClassProc:= 10;
hla.cClassIter := 11;
hla.cMethod:= 12;
hla.cMacro:= 13;
hla.cKeyword:= 14;
hla.cTerminator:= 15;
hla.cRegEx:= 16;
hla.cProgram:= 17;
hla.cNamespace:= 18;
hla.cSegment := 19;
hla.cRegister:= 20;
hla.cNone := 21;


Emil_halim

thanks Sevag.

this is work correctly

program movMacro;

#include("stdlib.hhf");

#id( mov ) 

#macro mov( a , b );     
     #if( @class( a ) = hla.cVar )
          LEA( a , b );
     #else
          ~mov(a,b);
     #endif
#endmacro;

var
    m : int32;
       
begin movMacro;

   mov(m,eax);
     
end movMacro;


but i want to use the "&" symbol , so i tried to modify the mov macro , so that it checks if the first char of arg a is "&"
then remove it and use the lea instruction , i used @leftdel and @left but without successfully.

any help please?
   

Emil_halim


oh..... i did it.

here is it , may be it is useful for someone else.

program movMacro;

#include("stdlib.hhf");

#id( mov ) 

#macro mov( a , b ); 
     ? rem :string;
     ? mat :string;
     #if( @onechar( @string( a ) , '&' , rem , mat ))
           #if( @class( @text( rem ) ) = hla.cVar )
               LEA(  @text( rem ) , b );
           #else
               ~mov(a,b);   
           #endif
     #else
          ~mov(a,b);     
     #endif       
#endmacro;

static
    s : int32;

var
    m : int32;
       
begin movMacro;

   mov(&m,eax);
   
   mov(&s,ebx);
   
   mov(m,ecx);
   
   mov(s,edx);
   
   mov(10,esi);
     
end movMacro;


Sevag.K


nicely done and a good idea to boot.

personally, i don't like changing assembly instructions, but i think this is a good candidate for a modification to my 'move' macro.


Emil_halim


thanks a lot.

BTW what is your 'move' macro ?

Sevag.K


it's a very simple pushd( a ).. pop( b ) macro.  on second thought, i have decided to leave it that way since it would defeat the purpose of the macro.  it would be better to re-identify the mov instruction instead.

Emil_halim


i think hla already do that by using mov instruction when the 2 operands are memory.

 

Sevag.K


yes, but there is no such thing in assembly and sometimes i like to be able to see the distinction at a glance.