flat assembler
Message board for the users of flat assembler.

flat assembler > Main > get local variable pointer without " lea"?

Author
Thread Post new topic Reply to topic
celtic88



Joined: 26 Mar 2018
Posts: 4
hi all,

How can get local variable pointer Without " lea" , thank you

code

Code:
format PE GUI 4.0
entry start

include 'INCLUDE\win32ax.inc'

section '.text' code readable executable

  start:

proc Func
  local pDirectx:DWORD

  ;//lea eax, [pDirectx]

  mov eax, pDirectx       ;// Get  pDirectx Pointer   ??

  ret
endp      
Post 03 Apr 2018, 16:47
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 15912
Location: SDSS J140821.67+025733.2
celtic88 wrote:
How can get local variable pointer Without " lea" , thank you
LEA is the only way, unless you override MOV with your own macro.
Post 03 Apr 2018, 22:44
View user's profile Send private message Visit poster's website Reply with quote
CandyMan



Joined: 04 Sep 2009
Posts: 274
Location: film "CandyMan" directed through Bernard Rose OR Candy Shop
did you mean:
Code:
proc Func
local pDirectx:DWORD
mov eax,pDirectx-ebp       
mov eax,[ebp+eax]
ret
endp    
Post 03 Apr 2018, 22:48
View user's profile Send private message Reply with quote
ProMiNick



Joined: 24 Mar 2012
Posts: 168
Location: Russian Federation, Sochi
in current example
mov eax, pDirectx equivalent to mov eax,esp or...
... or (only because macro proc used) equivalent to mov eax,ebp
if locals will be more than 1 dword so analog for lea will be 2 instructions instead of one lea, one of them is mov described previously & second is add or sub instruction with value equal to address range from esp (or ebp) to pointer to thour variable
Post 03 Apr 2018, 22:49
View user's profile Send private message Send e-mail Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 15912
Location: SDSS J140821.67+025733.2
LEA is just an ADD in disguise.
Code:
add eax,ebp,offset ;same as lea eax,[ebp+offset]    
But of course is won't assemble because Intel never defined the opcode ADD that way.
Post 03 Apr 2018, 22:53
View user's profile Send private message Visit poster's website Reply with quote
celtic88



Joined: 26 Mar 2018
Posts: 4
Currently I use this method!!


Code:
macro LocalPoint localV,localP {LEA eax, [localV]
mov [localP], eax}

proc Func 
  local pDirectx:DWORD,p_pDirectx:DWORD
  LocalPoint pDirectx,p_pDirectx
  ;//lea eax, [pDirectx] 

  mov eax, pDirectx       ;// Get  pDirectx Pointer   ?? 

  ret 
endp      
Post 04 Apr 2018, 07:40
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 15912
Location: SDSS J140821.67+025733.2
celtic88 wrote:
Currently I use this method!!


Code:
macro LocalPoint localV,localP {LEA eax, [localV]
mov [localP], eax}

proc Func 
  local pDirectx:DWORD,p_pDirectx:DWORD
  LocalPoint pDirectx,p_pDirectx
  ;//lea eax, [pDirectx] 

  mov eax, pDirectx       ;// Get  pDirectx Pointer   ?? 

  ret 
endp      
I don't understand why you would prefer to read a memory variable, instead of using the ALU to compute the value directly with lea. To me it looks like more work for the CPU and more work for the programmer. Maybe you have a particular purpose for it?
Post 04 Apr 2018, 08:02
View user's profile Send private message Visit poster's website Reply with quote
celtic88



Joined: 26 Mar 2018
Posts: 4
to do this


Code:
proc main
  local testt:DWORD
  
  LEA eax, [testt]
  
  stdcall Set,eax ;; i liked this syntax stdcall Set,test
  
  MOV eax, [testt]
  ret
endp
  
proc Set varbypoint
  MOV eax,[varbypoint]
  MOV dword [eax], 404
  ret
endp
    
Post 04 Apr 2018, 19:01
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 15912
Location: SDSS J140821.67+025733.2
You can use addr
Code:
stdcall Func,addr testt    
Less typing for the programmer, and more readable IMO. You just need to be aware that the standard macros will use edx for the temporary holder, whereas you used eax.
Post 04 Apr 2018, 22:29
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2018, Tomasz Grysztar.

Powered by rwasa.